diff --git a/OWASP DATASET/BenchmarkTest00001.java b/OWASP DATASET/BenchmarkTest00001.java new file mode 100644 index 0000000000000000000000000000000000000000..34c82096ba8bc1b35e854522226ae1b18dff3ae4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00001.java @@ -0,0 +1,105 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00001") +public class BenchmarkTest00001 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00001", "FileName"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/pathtraver-00/BenchmarkTest00001.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00001")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + param; + fis = new java.io.FileInputStream(new java.io.File(fileName)); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting FileInputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00002.java b/OWASP DATASET/BenchmarkTest00002.java new file mode 100644 index 0000000000000000000000000000000000000000..b31b6a33439aa4039fdd195a033f7f849eb26ea4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00002.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00002") +public class BenchmarkTest00002 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00002", "FileName"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/pathtraver-00/BenchmarkTest00002.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00002")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + param; + + fos = new java.io.FileOutputStream(fileName, false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00003.java b/OWASP DATASET/BenchmarkTest00003.java new file mode 100644 index 0000000000000000000000000000000000000000..501535c874b67daac6e9d139c8518dbcb02cef12 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00003.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00003") +public class BenchmarkTest00003 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00003", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/hash-00/BenchmarkTest00003.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00003")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = param; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00004.java b/OWASP DATASET/BenchmarkTest00004.java new file mode 100644 index 0000000000000000000000000000000000000000..beaa3b25c742434e54f55a41927c1b713a32d32d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00004.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00004") +public class BenchmarkTest00004 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00004", "color"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/trustbound-00/BenchmarkTest00004.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00004")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String^,java.lang.Object) + request.getSession().setAttribute(param, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(param) + + "' with value: '10340' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00005.java b/OWASP DATASET/BenchmarkTest00005.java new file mode 100644 index 0000000000000000000000000000000000000000..64ea4187ef3155544bbafed5ff2b2c500a20e8f2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00005.java @@ -0,0 +1,122 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00005") +public class BenchmarkTest00005 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00005") != null) { + param = request.getHeader("BenchmarkTest00005"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = param; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00006.java b/OWASP DATASET/BenchmarkTest00006.java new file mode 100644 index 0000000000000000000000000000000000000000..2359c9ba862113eb91cf1186df6cf38c778e4187 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00006.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00006") +public class BenchmarkTest00006 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00006") != null) { + param = request.getHeader("BenchmarkTest00006"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + param); + + ProcessBuilder pb = new ProcessBuilder(); + + pb.command(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00007.java b/OWASP DATASET/BenchmarkTest00007.java new file mode 100644 index 0000000000000000000000000000000000000000..d1d180aa9f6c2b30f93c1c6b2dc27361eaaea7c9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00007.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00007") +public class BenchmarkTest00007 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00007") != null) { + param = request.getHeader("BenchmarkTest00007"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {param}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00008.java b/OWASP DATASET/BenchmarkTest00008.java new file mode 100644 index 0000000000000000000000000000000000000000..3d2710eec4492292c190f7e8021c30a10496d344 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00008.java @@ -0,0 +1,68 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00008") +public class BenchmarkTest00008 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00008") != null) { + param = request.getHeader("BenchmarkTest00008"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String sql = "{call " + param + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = connection.prepareCall(sql); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00009.java b/OWASP DATASET/BenchmarkTest00009.java new file mode 100644 index 0000000000000000000000000000000000000000..abe18a4e5721040eec4af6da80b9426b38bab1c0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00009.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00009") +public class BenchmarkTest00009 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("sha-384", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("sha-384", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = param; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00010.java b/OWASP DATASET/BenchmarkTest00010.java new file mode 100644 index 0000000000000000000000000000000000000000..2a083966ec9bb4f97e61b6fd4957df646f7d6bd9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00010.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00010") +public class BenchmarkTest00010 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + try { + int randNumber = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "SafeInga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt(int) - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt(int) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00011.java b/OWASP DATASET/BenchmarkTest00011.java new file mode 100644 index 0000000000000000000000000000000000000000..cfda6fb0fa0f96d9e5586709122f15abfe0f8f94 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00011.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00011") +public class BenchmarkTest00011 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00011"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + java.io.File fileTarget = new java.io.File(param, "/Test.txt"); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00012.java b/OWASP DATASET/BenchmarkTest00012.java new file mode 100644 index 0000000000000000000000000000000000000000..5be39e80f906e2bdd567d3798ee2f09cff1904fa --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00012.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest00012") +public class BenchmarkTest00012 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00012"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + param + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + + javax.naming.directory.DirContext ctx = ads.getDirContext(); + javax.naming.directory.InitialDirContext idc = + (javax.naming.directory.InitialDirContext) ctx; + boolean found = false; + javax.naming.NamingEnumeration results = + idc.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00013.java b/OWASP DATASET/BenchmarkTest00013.java new file mode 100644 index 0000000000000000000000000000000000000000..0073b0e90d2f0871cbef7b879b6fe24089f725b1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00013.java @@ -0,0 +1,58 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00013") +public class BenchmarkTest00013 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(java.util.Locale.US, param, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00014.java b/OWASP DATASET/BenchmarkTest00014.java new file mode 100644 index 0000000000000000000000000000000000000000..2038ab9f06f1a86b200df9ac1ffb5d4b0022c27c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00014.java @@ -0,0 +1,58 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00014") +public class BenchmarkTest00014 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(param, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00015.java b/OWASP DATASET/BenchmarkTest00015.java new file mode 100644 index 0000000000000000000000000000000000000000..4f4f57ff5d8acb3d1d9e8d16fbe7eede8e27de6d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00015.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00015") +public class BenchmarkTest00015 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00015"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + param); + + ProcessBuilder pb = new ProcessBuilder(); + + pb.command(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00016.java b/OWASP DATASET/BenchmarkTest00016.java new file mode 100644 index 0000000000000000000000000000000000000000..cfa38dee89f68e1e91def05eee8acddd3cdf3bb5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00016.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest00016") +public class BenchmarkTest00016 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00016"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00017.java b/OWASP DATASET/BenchmarkTest00017.java new file mode 100644 index 0000000000000000000000000000000000000000..b022e9160cf5ec4cb20bcace8b95ad3ce85e5af5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00017.java @@ -0,0 +1,72 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00017") +public class BenchmarkTest00017 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00017"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + param); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00018.java b/OWASP DATASET/BenchmarkTest00018.java new file mode 100644 index 0000000000000000000000000000000000000000..df9dae2ab50bd0634b0c224b31bdb8a43b97b29b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00018.java @@ -0,0 +1,68 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00018") +public class BenchmarkTest00018 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00018"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + param + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00019.java b/OWASP DATASET/BenchmarkTest00019.java new file mode 100644 index 0000000000000000000000000000000000000000..f3fddb73d17783734e2055015d63ffdfe731abc6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00019.java @@ -0,0 +1,107 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00019") +public class BenchmarkTest00019 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + java.io.InputStream param = request.getInputStream(); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = param; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00020.java b/OWASP DATASET/BenchmarkTest00020.java new file mode 100644 index 0000000000000000000000000000000000000000..33266ef3e6a21f85fba7b57fa2ed2cce87b7a3bb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00020.java @@ -0,0 +1,151 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00020") +public class BenchmarkTest00020 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00020"); + if (param == null) param = ""; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = param; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00021.java b/OWASP DATASET/BenchmarkTest00021.java new file mode 100644 index 0000000000000000000000000000000000000000..0b469a363f74833345e5db3aa1fb0f910b9fe871 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00021.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest00021") +public class BenchmarkTest00021 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00021"); + if (param == null) param = ""; + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + javax.naming.directory.DirContext ctx = ads.getDirContext(); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + param + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + // System.out.println("Filter " + filter); + boolean found = false; + javax.naming.NamingEnumeration results = + ctx.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00022.java b/OWASP DATASET/BenchmarkTest00022.java new file mode 100644 index 0000000000000000000000000000000000000000..b9c8ae630e9bac8b664a2dd84ab1b0118ec38181 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00022.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00022") +public class BenchmarkTest00022 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00022"); + if (param == null) param = ""; + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-256"); + byte[] input = {(byte) '?'}; + Object inputParam = param; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00023.java b/OWASP DATASET/BenchmarkTest00023.java new file mode 100644 index 0000000000000000000000000000000000000000..a26bb3eb4418ac3669e12e205ec9945b6d1ba021 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00023.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00023") +public class BenchmarkTest00023 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00023"); + if (param == null) param = ""; + + float rand = new java.util.Random().nextFloat(); + String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "Floyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00024.java b/OWASP DATASET/BenchmarkTest00024.java new file mode 100644 index 0000000000000000000000000000000000000000..a43678bea54ad1fb2417c4b088d17615f203b72f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00024.java @@ -0,0 +1,68 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00024") +public class BenchmarkTest00024 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00024"); + if (param == null) param = ""; + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + param + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00025.java b/OWASP DATASET/BenchmarkTest00025.java new file mode 100644 index 0000000000000000000000000000000000000000..051a1c7ba6fabd10c3158513afb2fb6135faa790 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00025.java @@ -0,0 +1,66 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00025") +public class BenchmarkTest00025 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00025"); + if (param == null) param = ""; + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + param + "'"; + try { + // Long results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForLong(sql); + Long results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Long.class); + response.getWriter().println("Your results are: " + String.valueOf(results)); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00026.java b/OWASP DATASET/BenchmarkTest00026.java new file mode 100644 index 0000000000000000000000000000000000000000..dcdda026919e9b7c4ff656c1f22ac4e78264feb4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00026.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00026") +public class BenchmarkTest00026 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00026"); + if (param == null) param = ""; + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + param + "'"; + try { + org.springframework.jdbc.support.rowset.SqlRowSet results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForRowSet(sql); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + while (results.next()) { + response.getWriter() + .println( + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(results.getString("USERNAME")) + + " "); + // System.out.println(results.getString("USERNAME")); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00027.java b/OWASP DATASET/BenchmarkTest00027.java new file mode 100644 index 0000000000000000000000000000000000000000..27344a048a99114f397b0fd2f3840540d4590ec2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00027.java @@ -0,0 +1,61 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00027") +public class BenchmarkTest00027 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00027"); + if (param == null) param = ""; + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + param + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00028.java b/OWASP DATASET/BenchmarkTest00028.java new file mode 100644 index 0000000000000000000000000000000000000000..265945d77ed0de865d42b2502b731fde9a1f2a09 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00028.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00028") +public class BenchmarkTest00028 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00028"); + if (values != null) param = values[0]; + } + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + param; + + fos = new java.io.FileOutputStream(fileName, false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00029.java b/OWASP DATASET/BenchmarkTest00029.java new file mode 100644 index 0000000000000000000000000000000000000000..f0ea91e0c2712c141e3eb22632597f8f8dd9fa43 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00029.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00029") +public class BenchmarkTest00029 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00029"); + if (values != null) param = values[0]; + } + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = param; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00030.java b/OWASP DATASET/BenchmarkTest00030.java new file mode 100644 index 0000000000000000000000000000000000000000..5077e0d9d7118f3bd354ed558a4fba2fbf1a6b0c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00030.java @@ -0,0 +1,55 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00030") +public class BenchmarkTest00030 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00030"); + if (values != null) param = values[0]; + } + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(param, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00031.java b/OWASP DATASET/BenchmarkTest00031.java new file mode 100644 index 0000000000000000000000000000000000000000..bfc2971c714a4a4fd9b064339087d1ad54936e2b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00031.java @@ -0,0 +1,60 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00031") +public class BenchmarkTest00031 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00031"); + if (values != null) param = values[0]; + } + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", param); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(param) + + "' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00032.java b/OWASP DATASET/BenchmarkTest00032.java new file mode 100644 index 0000000000000000000000000000000000000000..2f829c2918e4e31128ae2c9110d7b4997c832eb4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00032.java @@ -0,0 +1,68 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00032") +public class BenchmarkTest00032 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00032"); + if (values != null) param = values[0]; + } + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + param + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.execute(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring execute method doesn't return results."); + + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00033.java b/OWASP DATASET/BenchmarkTest00033.java new file mode 100644 index 0000000000000000000000000000000000000000..bcfa5d1d4f3d8c82733adca517a520ce76207154 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00033.java @@ -0,0 +1,80 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00033") +public class BenchmarkTest00033 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00033"); + if (values != null) param = values[0]; + } + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + param + "'"; + try { + org.springframework.jdbc.support.rowset.SqlRowSet results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForRowSet(sql); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + while (results.next()) { + response.getWriter() + .println( + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(results.getString("USERNAME")) + + " "); + // System.out.println(results.getString("USERNAME")); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00034.java b/OWASP DATASET/BenchmarkTest00034.java new file mode 100644 index 0000000000000000000000000000000000000000..a4967179a23d14d0a1d277c7f083654939fc0eda --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00034.java @@ -0,0 +1,65 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00034") +public class BenchmarkTest00034 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00034"); + if (values != null) param = values[0]; + } + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + param + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00035.java b/OWASP DATASET/BenchmarkTest00035.java new file mode 100644 index 0000000000000000000000000000000000000000..59328d36a9dea39aa9ee7f19f35c150b20d82d78 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00035.java @@ -0,0 +1,122 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00035") +public class BenchmarkTest00035 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00035")) { + param = name; + flag = false; + } + } + } + } + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = param; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00036.java b/OWASP DATASET/BenchmarkTest00036.java new file mode 100644 index 0000000000000000000000000000000000000000..2b6c4576230b373fb0d184d949412f856dafd5aa --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00036.java @@ -0,0 +1,68 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00036") +public class BenchmarkTest00036 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00036")) { + param = name; + flag = false; + } + } + } + } + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (param != null) { + length = param.length(); + response.getWriter().write(param.toCharArray(), 0, length); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00037.java b/OWASP DATASET/BenchmarkTest00037.java new file mode 100644 index 0000000000000000000000000000000000000000..e3babd8a10b460c3cbec769c3db9a7ddb6138ab3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00037.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00037") +public class BenchmarkTest00037 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00037")) { + param = name; + flag = false; + } + } + } + } + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + param + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00038.java b/OWASP DATASET/BenchmarkTest00038.java new file mode 100644 index 0000000000000000000000000000000000000000..afd267f13c7200efbe08c9df16c2bcadce23f751 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00038.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00038") +public class BenchmarkTest00038 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00038")) { + param = name; + flag = false; + } + } + } + } + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + param + "'"; + try { + java.util.List results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.query( + sql, + new org.springframework.jdbc.core.RowMapper() { + @Override + public String mapRow(java.sql.ResultSet rs, int rowNum) + throws java.sql.SQLException { + try { + return rs.getString("USERNAME"); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper + .hideSQLErrors) { + return "Error processing query."; + } else throw e; + } + } + }); + response.getWriter().println("Your results are: "); + + for (String s : results) { + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(s) + "
"); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00039.java b/OWASP DATASET/BenchmarkTest00039.java new file mode 100644 index 0000000000000000000000000000000000000000..d4fce4685bd9cc44981befeaa0473c0fd4dc513f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00039.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00039") +public class BenchmarkTest00039 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00039")) { + param = name; + flag = false; + } + } + } + } + + String sql = + "SELECT TOP 1 userid from USERS where USERNAME='foo' and PASSWORD='" + param + "'"; + try { + java.util.Map results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForMap(sql); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(results.toString())); + // System.out.println(results.toString()); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00040.java b/OWASP DATASET/BenchmarkTest00040.java new file mode 100644 index 0000000000000000000000000000000000000000..71bc125e2c9ca66cc4399f25199eda74a81459c7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00040.java @@ -0,0 +1,65 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00040") +public class BenchmarkTest00040 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00040"); + if (param == null) param = ""; + + java.io.File fileTarget = new java.io.File(param); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00041.java b/OWASP DATASET/BenchmarkTest00041.java new file mode 100644 index 0000000000000000000000000000000000000000..98e58d1dce35f599b8edc0a3717986808431a324 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00041.java @@ -0,0 +1,56 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00041") +public class BenchmarkTest00041 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00041"); + if (param == null) param = ""; + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (param != null) { + length = param.length(); + response.getWriter().write(param, 0, length); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00042.java b/OWASP DATASET/BenchmarkTest00042.java new file mode 100644 index 0000000000000000000000000000000000000000..dfa3e8ff397f92d068c48b5718a2f7292f28e603 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00042.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00042") +public class BenchmarkTest00042 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00042"); + if (param == null) param = ""; + + try { + int r = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "SafeIngrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00043.java b/OWASP DATASET/BenchmarkTest00043.java new file mode 100644 index 0000000000000000000000000000000000000000..e20d25a567a6a3ccdfd83999ce932e0c20b75dbe --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00043.java @@ -0,0 +1,63 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00043") +public class BenchmarkTest00043 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00043"); + if (param == null) param = ""; + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + param + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00044.java b/OWASP DATASET/BenchmarkTest00044.java new file mode 100644 index 0000000000000000000000000000000000000000..58d299d61993e228b8626c872e40d7fdb84df3b5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00044.java @@ -0,0 +1,98 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest00044") +public class BenchmarkTest00044 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00044"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + javax.naming.directory.DirContext ctx = ads.getDirContext(); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person)(uid=" + param + "))"; + // System.out.println("Filter " + filter); + boolean found = false; + javax.naming.NamingEnumeration results = + ctx.search(base, filter, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00045.java b/OWASP DATASET/BenchmarkTest00045.java new file mode 100644 index 0000000000000000000000000000000000000000..f425d61a1e38d6eafdac907103cf5bd8b89d940e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00045.java @@ -0,0 +1,72 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00045") +public class BenchmarkTest00045 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00045"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + param; + + try ( + // Create the file first so the test won't throw an exception if it doesn't exist. + // Note: Don't actually do this because this method signature could cause a tool to find + // THIS file constructor + // as a vuln, rather than the File signature we are trying to actually test. + // If necessary, just run the benchmark twice. The 1st run should create all the necessary + // files. + // new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + + // param).createNewFile(); + + java.io.FileOutputStream fos = + new java.io.FileOutputStream(new java.io.FileInputStream(fileName).getFD()); ) { + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00046.java b/OWASP DATASET/BenchmarkTest00046.java new file mode 100644 index 0000000000000000000000000000000000000000..4956e4a9b52f7daff93c098dbfde0d419efe9dfc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00046.java @@ -0,0 +1,98 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00046") +public class BenchmarkTest00046 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00046"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); + byte[] input = {(byte) '?'}; + Object inputParam = param; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00047.java b/OWASP DATASET/BenchmarkTest00047.java new file mode 100644 index 0000000000000000000000000000000000000000..59f12dc1788df96210819a3eb0b20ba3ee39e473 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00047.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00047") +public class BenchmarkTest00047 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00047" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00047" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00047" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(param, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00048.java b/OWASP DATASET/BenchmarkTest00048.java new file mode 100644 index 0000000000000000000000000000000000000000..b528f008ecd1696ef8f2ac78dc159760b883e09e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00048.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00048") +public class BenchmarkTest00048 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00048" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00048" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00048" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(param.toCharArray()); + } +} diff --git a/OWASP DATASET/BenchmarkTest00049.java b/OWASP DATASET/BenchmarkTest00049.java new file mode 100644 index 0000000000000000000000000000000000000000..c3b0e43c70f41948dc6a3e7de63a0298cd713c27 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00049.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00049") +public class BenchmarkTest00049 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00049" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00049" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00049" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write("Parameter value: " + param); + } +} diff --git a/OWASP DATASET/BenchmarkTest00050.java b/OWASP DATASET/BenchmarkTest00050.java new file mode 100644 index 0000000000000000000000000000000000000000..2f74b7bb3415842f2fd03a365c4c99a2556a8284 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00050.java @@ -0,0 +1,152 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00050") +public class BenchmarkTest00050 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00050"); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = param; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00051.java b/OWASP DATASET/BenchmarkTest00051.java new file mode 100644 index 0000000000000000000000000000000000000000..b9ec7bb47c45ef4fc84b2e7bdd5e29eabae6ac69 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00051.java @@ -0,0 +1,71 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00051") +public class BenchmarkTest00051 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00051"); + + String a1 = ""; + String a2 = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + } else { + a1 = "sh"; + a2 = "-c"; + } + String[] args = {a1, a2, "echo " + param}; + + ProcessBuilder pb = new ProcessBuilder(args); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.lang.String[]) Test Case"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00052.java b/OWASP DATASET/BenchmarkTest00052.java new file mode 100644 index 0000000000000000000000000000000000000000..caa0f146155e5ae5e6fa1a55a90716beda4d9e94 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00052.java @@ -0,0 +1,68 @@ +/** + * OWASP Benchmark v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00052") +public class BenchmarkTest00052 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // some code + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00052"); + + String sql = "{call " + param + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00053.java b/OWASP DATASET/BenchmarkTest00053.java new file mode 100644 index 0000000000000000000000000000000000000000..d2b0b30ed13a49f645ef11cfc9b79d7a3bcc97e4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00053.java @@ -0,0 +1,172 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00053") +public class BenchmarkTest00053 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00053", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/crypto-00/BenchmarkTest00053.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00053")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "DES/CBC/PKCS5PADDING", java.security.Security.getProvider("SunJCE")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00054.java b/OWASP DATASET/BenchmarkTest00054.java new file mode 100644 index 0000000000000000000000000000000000000000..f7686414626be33f222cd1965aa7074bf61bc13b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00054.java @@ -0,0 +1,168 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00054") +public class BenchmarkTest00054 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00054", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/crypto-00/BenchmarkTest00054.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00054")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = param; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00055.java b/OWASP DATASET/BenchmarkTest00055.java new file mode 100644 index 0000000000000000000000000000000000000000..23bd9f8d49c8216cee021ea44bd3fcec0d18a5c1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00055.java @@ -0,0 +1,171 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00055") +public class BenchmarkTest00055 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00055", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/crypto-00/BenchmarkTest00055.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00055")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = param; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00056.java b/OWASP DATASET/BenchmarkTest00056.java new file mode 100644 index 0000000000000000000000000000000000000000..29390d61909e51b1759fdbc6e67bcee02440f67d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00056.java @@ -0,0 +1,181 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00056") +public class BenchmarkTest00056 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00056", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/crypto-00/BenchmarkTest00056.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00056")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00057.java b/OWASP DATASET/BenchmarkTest00057.java new file mode 100644 index 0000000000000000000000000000000000000000..4ef862d5aea7e09b735da54ec7c99b611b201263 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00057.java @@ -0,0 +1,142 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00057") +public class BenchmarkTest00057 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00057", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/crypto-00/BenchmarkTest00057.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00057")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00058.java b/OWASP DATASET/BenchmarkTest00058.java new file mode 100644 index 0000000000000000000000000000000000000000..7d03df2bafb543c77a0b738f522f8c036514bd3b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00058.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00058") +public class BenchmarkTest00058 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00058", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/crypto-00/BenchmarkTest00058.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00058")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = param; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "AES/CCM/NoPadding", java.security.Security.getProvider("BC")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00059.java b/OWASP DATASET/BenchmarkTest00059.java new file mode 100644 index 0000000000000000000000000000000000000000..2a138ea63b14d662f8ae0d8b3bca0d548c80e710 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00059.java @@ -0,0 +1,139 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00059") +public class BenchmarkTest00059 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00059", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/crypto-00/BenchmarkTest00059.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00059")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + StringBuilder sbxyz22532 = new StringBuilder(param); + String bar = sbxyz22532.append("_SafeStuff").toString(); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + // java.security.SecureRandom random = new java.security.SecureRandom(); + // byte[] iv = random.generateSeed(16); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg2", "AES/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00060.java b/OWASP DATASET/BenchmarkTest00060.java new file mode 100644 index 0000000000000000000000000000000000000000..a64f933d3e74a454dbaad3cfabc389bcfa0aee25 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00060.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00060") +public class BenchmarkTest00060 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00060", "FileName"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/pathtraver-00/BenchmarkTest00060.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00060")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00061.java b/OWASP DATASET/BenchmarkTest00061.java new file mode 100644 index 0000000000000000000000000000000000000000..e0d2e0036902f16a24ed8b68ace8aeca63a25fc2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00061.java @@ -0,0 +1,90 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00061") +public class BenchmarkTest00061 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00061", "FileName"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/pathtraver-00/BenchmarkTest00061.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00061")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + java.io.File fileTarget = new java.io.File(bar, "/Test.txt"); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00062.java b/OWASP DATASET/BenchmarkTest00062.java new file mode 100644 index 0000000000000000000000000000000000000000..44f0ea70b7727b314804f7765b44dddeddad5632 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00062.java @@ -0,0 +1,111 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00062") +public class BenchmarkTest00062 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00062", "FileName"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/pathtraver-00/BenchmarkTest00062.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00062")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = "safe!"; + java.util.HashMap map77232 = new java.util.HashMap(); + map77232.put("keyA-77232", "a-Value"); // put some stuff in the collection + map77232.put("keyB-77232", param); // put it in a collection + map77232.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map77232.get("keyB-77232"); // get it back out + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(new java.io.File(fileName)); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting FileInputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00063.java b/OWASP DATASET/BenchmarkTest00063.java new file mode 100644 index 0000000000000000000000000000000000000000..3e9550a7ea3ecaf69b2efeac11adafb936fefcb8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00063.java @@ -0,0 +1,111 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00063") +public class BenchmarkTest00063 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00063", "FileName"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/pathtraver-00/BenchmarkTest00063.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00063")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(new java.io.File(fileName)); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting FileInputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00064.java b/OWASP DATASET/BenchmarkTest00064.java new file mode 100644 index 0000000000000000000000000000000000000000..79a829e3b4d877a7b17d5dc58b2873f4f352a0ef --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00064.java @@ -0,0 +1,98 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00064") +public class BenchmarkTest00064 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00064", "FileName"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/pathtraver-00/BenchmarkTest00064.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00064")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00065.java b/OWASP DATASET/BenchmarkTest00065.java new file mode 100644 index 0000000000000000000000000000000000000000..483faac90e3d5986f71782ed8941132f556da1e2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00065.java @@ -0,0 +1,111 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00065") +public class BenchmarkTest00065 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00065", "FileName"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/pathtraver-00/BenchmarkTest00065.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00065")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + java.io.InputStream is = null; + + try { + java.nio.file.Path path = java.nio.file.Paths.get(fileName); + is = java.nio.file.Files.newInputStream(path, java.nio.file.StandardOpenOption.READ); + byte[] b = new byte[1000]; + int size = is.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + is.close(); + } catch (Exception e) { + System.out.println("Couldn't open InputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting InputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (is != null) { + try { + is.close(); + is = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00066.java b/OWASP DATASET/BenchmarkTest00066.java new file mode 100644 index 0000000000000000000000000000000000000000..81f632e6467ec6db014c11a64ae928acf49250fb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00066.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00066") +public class BenchmarkTest00066 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00066", "anything"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-00/BenchmarkTest00066.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00066")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + double value = java.lang.Math.random(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Doug"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + response.getWriter().println("Weak Randomness Test java.lang.Math.random() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00067.java b/OWASP DATASET/BenchmarkTest00067.java new file mode 100644 index 0000000000000000000000000000000000000000..625cb93271629698cad0963f5bbcf513775be5c9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00067.java @@ -0,0 +1,137 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00067") +public class BenchmarkTest00067 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00067", "anything"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-00/BenchmarkTest00067.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00067")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + // Chain a bunch of propagators in sequence + String a71153 = param; // assign + StringBuilder b71153 = new StringBuilder(a71153); // stick in stringbuilder + b71153.append(" SafeStuff"); // append some safe content + b71153.replace( + b71153.length() - "Chars".length(), + b71153.length(), + "Chars"); // replace some of the end content + java.util.HashMap map71153 = new java.util.HashMap(); + map71153.put("key71153", b71153.toString()); // put in a collection + String c71153 = (String) map71153.get("key71153"); // get it back out + String d71153 = c71153.substring(0, c71153.length() - 1); // extract most of it + String e71153 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d71153.getBytes()))); // B64 encode and decode it + String f71153 = e71153.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g71153 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g71153); // reflection + + double value = java.lang.Math.random(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Doug"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + response.getWriter().println("Weak Randomness Test java.lang.Math.random() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00068.java b/OWASP DATASET/BenchmarkTest00068.java new file mode 100644 index 0000000000000000000000000000000000000000..a767d4fed3ed52376f115f8f46666d6685de1ae2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00068.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00068") +public class BenchmarkTest00068 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00068", "anything"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-00/BenchmarkTest00068.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00068")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + double value = java.lang.Math.random(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Doug"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + response.getWriter().println("Weak Randomness Test java.lang.Math.random() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00069.java b/OWASP DATASET/BenchmarkTest00069.java new file mode 100644 index 0000000000000000000000000000000000000000..508d372969bc7c2886a63e4dfe343ee6d9f292a4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00069.java @@ -0,0 +1,134 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00069") +public class BenchmarkTest00069 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00069", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/hash-00/BenchmarkTest00069.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00069")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("sha-384", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("sha-384", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00070.java b/OWASP DATASET/BenchmarkTest00070.java new file mode 100644 index 0000000000000000000000000000000000000000..594071e2b8ee97034f17f444fdf6c4d1f8f8da90 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00070.java @@ -0,0 +1,126 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00070") +public class BenchmarkTest00070 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00070", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/hash-00/BenchmarkTest00070.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00070")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00071.java b/OWASP DATASET/BenchmarkTest00071.java new file mode 100644 index 0000000000000000000000000000000000000000..a2400b31c9f01d6a93f2694596f78b5145255bcb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00071.java @@ -0,0 +1,126 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00071") +public class BenchmarkTest00071 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00071", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/hash-00/BenchmarkTest00071.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00071")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00072.java b/OWASP DATASET/BenchmarkTest00072.java new file mode 100644 index 0000000000000000000000000000000000000000..afa3284c5724b21f852d8e1852e4c98b237938eb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00072.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00072") +public class BenchmarkTest00072 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00072", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/hash-00/BenchmarkTest00072.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00072")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + try { + java.security.MessageDigest md = + java.security.MessageDigest.getInstance("SHA-512", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00073.java b/OWASP DATASET/BenchmarkTest00073.java new file mode 100644 index 0000000000000000000000000000000000000000..6aa740440aa0c47984fe3a82efb5ee5d912814c1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00073.java @@ -0,0 +1,135 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00073") +public class BenchmarkTest00073 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00073", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/hash-00/BenchmarkTest00073.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00073")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00074.java b/OWASP DATASET/BenchmarkTest00074.java new file mode 100644 index 0000000000000000000000000000000000000000..b1cc4ddfc2bb4aa03c56a8526113afa0cebaef40 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00074.java @@ -0,0 +1,125 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00074") +public class BenchmarkTest00074 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00074", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/hash-00/BenchmarkTest00074.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00074")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = "safe!"; + java.util.HashMap map98790 = new java.util.HashMap(); + map98790.put("keyA-98790", "a-Value"); // put some stuff in the collection + map98790.put("keyB-98790", param); // put it in a collection + map98790.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map98790.get("keyB-98790"); // get it back out + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00075.java b/OWASP DATASET/BenchmarkTest00075.java new file mode 100644 index 0000000000000000000000000000000000000000..5722b0bc4c1c5fb4e21e1e647b0299823029d327 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00075.java @@ -0,0 +1,125 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00075") +public class BenchmarkTest00075 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00075", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/hash-00/BenchmarkTest00075.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00075")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00076.java b/OWASP DATASET/BenchmarkTest00076.java new file mode 100644 index 0000000000000000000000000000000000000000..3b38ebb83c80abcb4c441c92e151e4179a1bf9e4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00076.java @@ -0,0 +1,139 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00076") +public class BenchmarkTest00076 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00076", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/hash-00/BenchmarkTest00076.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00076")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00077.java b/OWASP DATASET/BenchmarkTest00077.java new file mode 100644 index 0000000000000000000000000000000000000000..d929ba69349ccda063630b5fac03ea3143b9fe97 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00077.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00077") +public class BenchmarkTest00077 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00077", "ECHOOO"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/cmdi-00/BenchmarkTest00077.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00077")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00078.java b/OWASP DATASET/BenchmarkTest00078.java new file mode 100644 index 0000000000000000000000000000000000000000..5773c9d2a4987fae84bdf6bee024f91a8f716675 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00078.java @@ -0,0 +1,123 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00078") +public class BenchmarkTest00078 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00078", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-00/BenchmarkTest00078.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00078")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + float rand = new java.util.Random().nextFloat(); + String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "Floyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00079.java b/OWASP DATASET/BenchmarkTest00079.java new file mode 100644 index 0000000000000000000000000000000000000000..0cc7c196d807ae7f1d699c7c410e1b9223cf9937 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00079.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00079") +public class BenchmarkTest00079 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00079", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-00/BenchmarkTest00079.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00079")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = "safe!"; + java.util.HashMap map18384 = new java.util.HashMap(); + map18384.put("keyA-18384", "a-Value"); // put some stuff in the collection + map18384.put("keyB-18384", param); // put it in a collection + map18384.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map18384.get("keyB-18384"); // get it back out + + float rand = new java.util.Random().nextFloat(); + String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "Floyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00080.java b/OWASP DATASET/BenchmarkTest00080.java new file mode 100644 index 0000000000000000000000000000000000000000..b39fc2434f8515ba5cd98336b6683bcf7b6be2cf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00080.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00080") +public class BenchmarkTest00080 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00080", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-00/BenchmarkTest00080.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00080")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + float rand = new java.util.Random().nextFloat(); + String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "Floyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00081.java b/OWASP DATASET/BenchmarkTest00081.java new file mode 100644 index 0000000000000000000000000000000000000000..a0b486ee756b7a5dcfafa8b9630f33e6e35b11bd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00081.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00081") +public class BenchmarkTest00081 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00081", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-00/BenchmarkTest00081.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00081")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + double stuff = new java.util.Random().nextGaussian(); + String rememberMeKey = Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "Gayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter() + .println("Weak Randomness Test java.util.Random.nextGaussian() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00082.java b/OWASP DATASET/BenchmarkTest00082.java new file mode 100644 index 0000000000000000000000000000000000000000..c0de01c39c2186f69a8bb8919d2afa9845df2943 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00082.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00082") +public class BenchmarkTest00082 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00082", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-00/BenchmarkTest00082.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00082")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + StringBuilder sbxyz58640 = new StringBuilder(param); + String bar = sbxyz58640.append("_SafeStuff").toString(); + + int randNumber = new java.util.Random().nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "Inga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt(int) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00083.java b/OWASP DATASET/BenchmarkTest00083.java new file mode 100644 index 0000000000000000000000000000000000000000..6f509bf5deedf3fc8af646d0a4de945591964ecc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00083.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00083") +public class BenchmarkTest00083 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00083", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-00/BenchmarkTest00083.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00083")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + int randNumber = new java.util.Random().nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "Inga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt(int) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00084.java b/OWASP DATASET/BenchmarkTest00084.java new file mode 100644 index 0000000000000000000000000000000000000000..03c3eb0cb3e15083776cd54cf287cdda6ddb389e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00084.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00084") +public class BenchmarkTest00084 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00084", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-00/BenchmarkTest00084.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00084")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00085.java b/OWASP DATASET/BenchmarkTest00085.java new file mode 100644 index 0000000000000000000000000000000000000000..3cd977db9ea79ebc8e87b7dfb1a31c2c5147698d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00085.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00085") +public class BenchmarkTest00085 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00085", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-00/BenchmarkTest00085.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00085")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = "safe!"; + java.util.HashMap map43974 = new java.util.HashMap(); + map43974.put("keyA-43974", "a-Value"); // put some stuff in the collection + map43974.put("keyB-43974", param); // put it in a collection + map43974.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map43974.get("keyB-43974"); // get it back out + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00086.java b/OWASP DATASET/BenchmarkTest00086.java new file mode 100644 index 0000000000000000000000000000000000000000..cd31ec9742351aacdb7b4101415abf2481f2f7da --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00086.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00086") +public class BenchmarkTest00086 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00086", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-00/BenchmarkTest00086.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00086")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00087.java b/OWASP DATASET/BenchmarkTest00087.java new file mode 100644 index 0000000000000000000000000000000000000000..460086f96cb7a49e669f0be55c7dbac94ffdccd2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00087.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest00087") +public class BenchmarkTest00087 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00087", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/securecookie-00/BenchmarkTest00087.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00087")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00088.java b/OWASP DATASET/BenchmarkTest00088.java new file mode 100644 index 0000000000000000000000000000000000000000..4da339103388e400f33b02278a42aaba19331438 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00088.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest00088") +public class BenchmarkTest00088 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00088", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/securecookie-00/BenchmarkTest00088.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00088")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00089.java b/OWASP DATASET/BenchmarkTest00089.java new file mode 100644 index 0000000000000000000000000000000000000000..ff09d01f11e40222da0e54f4503d1f828406bd8c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00089.java @@ -0,0 +1,101 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest00089") +public class BenchmarkTest00089 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00089", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/securecookie-00/BenchmarkTest00089.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00089")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00090.java b/OWASP DATASET/BenchmarkTest00090.java new file mode 100644 index 0000000000000000000000000000000000000000..6f045cb9f0c939eaff680f52f58f1c07d734bf27 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00090.java @@ -0,0 +1,90 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00090") +public class BenchmarkTest00090 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00090", "ls"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/cmdi-00/BenchmarkTest00090.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00090")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00091.java b/OWASP DATASET/BenchmarkTest00091.java new file mode 100644 index 0000000000000000000000000000000000000000..4a983d3ca684def58aa8f7e6c4731b81d36b805b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00091.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00091") +public class BenchmarkTest00091 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00091", "FOO%3Decho+Injection"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/cmdi-00/BenchmarkTest00091.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00091")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = param; + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00092.java b/OWASP DATASET/BenchmarkTest00092.java new file mode 100644 index 0000000000000000000000000000000000000000..9421950e4329beb281ffa87fdb6f340d5abc2f6e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00092.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00092") +public class BenchmarkTest00092 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00092", "FOO%3Decho+Injection"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/cmdi-00/BenchmarkTest00092.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00092")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00093.java b/OWASP DATASET/BenchmarkTest00093.java new file mode 100644 index 0000000000000000000000000000000000000000..56372b8c82c29db48b1c24b1744d57c12e5ae18d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00093.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00093") +public class BenchmarkTest00093 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00093", "ls"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/cmdi-00/BenchmarkTest00093.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00093")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00094.java b/OWASP DATASET/BenchmarkTest00094.java new file mode 100644 index 0000000000000000000000000000000000000000..f6e2b83b29bb981a37c373e0fb124c7a4766600d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00094.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00094") +public class BenchmarkTest00094 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00094", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-00/BenchmarkTest00094.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00094")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = "safe!"; + java.util.HashMap map52993 = new java.util.HashMap(); + map52993.put("keyA-52993", "a_Value"); // put some stuff in the collection + map52993.put("keyB-52993", param); // put it in a collection + map52993.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map52993.get("keyB-52993"); // get it back out + bar = (String) map52993.get("keyA-52993"); // get safe value back out + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00095.java b/OWASP DATASET/BenchmarkTest00095.java new file mode 100644 index 0000000000000000000000000000000000000000..d817be4a47601ab42c9dbbd91024b71b0da210dc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00095.java @@ -0,0 +1,127 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00095") +public class BenchmarkTest00095 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00095", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-00/BenchmarkTest00095.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00095")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = "safe!"; + java.util.HashMap map45268 = new java.util.HashMap(); + map45268.put("keyA-45268", "a-Value"); // put some stuff in the collection + map45268.put("keyB-45268", param); // put it in a collection + map45268.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map45268.get("keyB-45268"); // get it back out + + try { + double stuff = java.security.SecureRandom.getInstance("SHA1PRNG").nextGaussian(); + String rememberMeKey = + Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "SafeGayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextGaussian() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextGaussian() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00096.java b/OWASP DATASET/BenchmarkTest00096.java new file mode 100644 index 0000000000000000000000000000000000000000..53537aea13157035ce1c0cd6813b04f6949bb448 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00096.java @@ -0,0 +1,126 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00096") +public class BenchmarkTest00096 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00096", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-00/BenchmarkTest00096.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00096")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + try { + int randNumber = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "SafeInga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt(int) - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt(int) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00097.java b/OWASP DATASET/BenchmarkTest00097.java new file mode 100644 index 0000000000000000000000000000000000000000..10fe45f85c739e9305381210932414a704f179fa --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00097.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00097") +public class BenchmarkTest00097 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00097", "color"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/trustbound-00/BenchmarkTest00097.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00097")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + // javax.servlet.http.HttpSession.putValue(java.lang.String^,java.lang.Object) + request.getSession().putValue(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: 10340 saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00098.java b/OWASP DATASET/BenchmarkTest00098.java new file mode 100644 index 0000000000000000000000000000000000000000..daeadc40ef3df37c103a60cff02b8db8ea78a89f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00098.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00098") +public class BenchmarkTest00098 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00098", "my_user_id"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/trustbound-00/BenchmarkTest00098.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00098")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00099.java b/OWASP DATASET/BenchmarkTest00099.java new file mode 100644 index 0000000000000000000000000000000000000000..bc8c41f1403f63976a0d68d05c69decd252bceaf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00099.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00099") +public class BenchmarkTest00099 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00099", "my_userid"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/trustbound-00/BenchmarkTest00099.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00099")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00100.java b/OWASP DATASET/BenchmarkTest00100.java new file mode 100644 index 0000000000000000000000000000000000000000..9e8349062c12465de8e5210fa8fdafc45505481e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00100.java @@ -0,0 +1,93 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00100") +public class BenchmarkTest00100 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00100", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-00/BenchmarkTest00100.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00100")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = "safe!"; + java.util.HashMap map72344 = new java.util.HashMap(); + map72344.put("keyA-72344", "a-Value"); // put some stuff in the collection + map72344.put("keyB-72344", param); // put it in a collection + map72344.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map72344.get("keyB-72344"); // get it back out + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00101.java b/OWASP DATASET/BenchmarkTest00101.java new file mode 100644 index 0000000000000000000000000000000000000000..3ed4c9a6a4407a50237b7804b5c4b807622d425e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00101.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00101") +public class BenchmarkTest00101 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00101", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-00/BenchmarkTest00101.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00101")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, new String[] {"Column1", "Column2"}); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00102.java b/OWASP DATASET/BenchmarkTest00102.java new file mode 100644 index 0000000000000000000000000000000000000000..f1b552dd7f75e00afd4ba141aefc5d51d40bcf64 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00102.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00102") +public class BenchmarkTest00102 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00102", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-00/BenchmarkTest00102.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00102")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + String sql = + "SELECT TOP 1 userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.Map results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForMap(sql); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(results.toString())); + // System.out.println(results.toString()); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00103.java b/OWASP DATASET/BenchmarkTest00103.java new file mode 100644 index 0000000000000000000000000000000000000000..d3845ed61d5adfb471d8f1a044e21bc79f78902d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00103.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00103") +public class BenchmarkTest00103 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00103", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-00/BenchmarkTest00103.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00103")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + String sql = + "SELECT TOP 1 USERNAME from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + Object results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, new Object[] {}, String.class); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(results.toString())); + // System.out.println(results.toString()); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00104.java b/OWASP DATASET/BenchmarkTest00104.java new file mode 100644 index 0000000000000000000000000000000000000000..2794ec8e110f0ed92c90a181e9c10d36fbd3117c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00104.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00104") +public class BenchmarkTest00104 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00104", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-00/BenchmarkTest00104.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00104")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00105.java b/OWASP DATASET/BenchmarkTest00105.java new file mode 100644 index 0000000000000000000000000000000000000000..6d5d0f5b5f6bf5b17d986bdbba9ef04dfe31fad6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00105.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00105") +public class BenchmarkTest00105 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00105", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-00/BenchmarkTest00105.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00105")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.addBatch(sql); + int[] counts = statement.executeBatch(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(sql, counts, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00106.java b/OWASP DATASET/BenchmarkTest00106.java new file mode 100644 index 0000000000000000000000000000000000000000..e844eb8d45662d9925c2b4fdd8ebfc41cff8a131 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00106.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00106") +public class BenchmarkTest00106 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00106", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-00/BenchmarkTest00106.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00106")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00107.java b/OWASP DATASET/BenchmarkTest00107.java new file mode 100644 index 0000000000000000000000000000000000000000..37994ba34533d823c0a09849a678fa5e70ebafbd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00107.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00107") +public class BenchmarkTest00107 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00107", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-00/BenchmarkTest00107.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00107")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + // Chain a bunch of propagators in sequence + String a18521 = param; // assign + StringBuilder b18521 = new StringBuilder(a18521); // stick in stringbuilder + b18521.append(" SafeStuff"); // append some safe content + b18521.replace( + b18521.length() - "Chars".length(), + b18521.length(), + "Chars"); // replace some of the end content + java.util.HashMap map18521 = new java.util.HashMap(); + map18521.put("key18521", b18521.toString()); // put in a collection + String c18521 = (String) map18521.get("key18521"); // get it back out + String d18521 = c18521.substring(0, c18521.length() - 1); // extract most of it + String e18521 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d18521.getBytes()))); // B64 encode and decode it + String f18521 = e18521.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g18521 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g18521); // reflection + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00108.java b/OWASP DATASET/BenchmarkTest00108.java new file mode 100644 index 0000000000000000000000000000000000000000..936abe85726edf31d63edce6a8222a9bb066bbdb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00108.java @@ -0,0 +1,100 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00108") +public class BenchmarkTest00108 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00108", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-00/BenchmarkTest00108.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00108")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00109.java b/OWASP DATASET/BenchmarkTest00109.java new file mode 100644 index 0000000000000000000000000000000000000000..2816bc4edc4c20d2ae806ce4cb1a35282d4bf8bd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00109.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00109") +public class BenchmarkTest00109 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00109", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-00/BenchmarkTest00109.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00109")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new String[] {"username", "password"}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00110.java b/OWASP DATASET/BenchmarkTest00110.java new file mode 100644 index 0000000000000000000000000000000000000000..3bb8262098e91b97e4081b89e2da777feaa3c1e1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00110.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00110") +public class BenchmarkTest00110 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00110", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-00/BenchmarkTest00110.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00110")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + // Chain a bunch of propagators in sequence + String a69840 = param; // assign + StringBuilder b69840 = new StringBuilder(a69840); // stick in stringbuilder + b69840.append(" SafeStuff"); // append some safe content + b69840.replace( + b69840.length() - "Chars".length(), + b69840.length(), + "Chars"); // replace some of the end content + java.util.HashMap map69840 = new java.util.HashMap(); + map69840.put("key69840", b69840.toString()); // put in a collection + String c69840 = (String) map69840.get("key69840"); // get it back out + String d69840 = c69840.substring(0, c69840.length() - 1); // extract most of it + String e69840 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d69840.getBytes()))); // B64 encode and decode it + String f69840 = e69840.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g69840 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g69840); // reflection + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new String[] {"username", "password"}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00111.java b/OWASP DATASET/BenchmarkTest00111.java new file mode 100644 index 0000000000000000000000000000000000000000..70ff23ca686b36ac1cfe826ed6894a6f44d4a9b6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00111.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00111") +public class BenchmarkTest00111 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00111", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-00/BenchmarkTest00111.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00111")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00112.java b/OWASP DATASET/BenchmarkTest00112.java new file mode 100644 index 0000000000000000000000000000000000000000..fdef001896579a783bfa3efd01526f686ed48536 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00112.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00112") +public class BenchmarkTest00112 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00112", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-00/BenchmarkTest00112.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00112")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00113.java b/OWASP DATASET/BenchmarkTest00113.java new file mode 100644 index 0000000000000000000000000000000000000000..fb9bc79c7cf94b7abdd0e90914efc139d921bcb4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00113.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00113") +public class BenchmarkTest00113 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00113", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-00/BenchmarkTest00113.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00113")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = "safe!"; + java.util.HashMap map21657 = new java.util.HashMap(); + map21657.put("keyA-21657", "a_Value"); // put some stuff in the collection + map21657.put("keyB-21657", param); // put it in a collection + map21657.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map21657.get("keyB-21657"); // get it back out + bar = (String) map21657.get("keyA-21657"); // get safe value back out + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00114.java b/OWASP DATASET/BenchmarkTest00114.java new file mode 100644 index 0000000000000000000000000000000000000000..996189bce35becaf16125afd788d60ca98511afb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00114.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00114") +public class BenchmarkTest00114 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00114", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-00/BenchmarkTest00114.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00114")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00115.java b/OWASP DATASET/BenchmarkTest00115.java new file mode 100644 index 0000000000000000000000000000000000000000..677548bb40a0ff883bc5c8406ec9683f2f394876 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00115.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00115") +public class BenchmarkTest00115 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00115", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-00/BenchmarkTest00115.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00115")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = "safe!"; + java.util.HashMap map11928 = new java.util.HashMap(); + map11928.put("keyA-11928", "a-Value"); // put some stuff in the collection + map11928.put("keyB-11928", param); // put it in a collection + map11928.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map11928.get("keyB-11928"); // get it back out + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new String[] {"USERNAME", "PASSWORD"}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00116.java b/OWASP DATASET/BenchmarkTest00116.java new file mode 100644 index 0000000000000000000000000000000000000000..6ffcc0b757ded030135c28c62b2c170f50f385dc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00116.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest00116") +public class BenchmarkTest00116 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00116", "2222"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/xpathi-00/BenchmarkTest00116.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00116")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = "safe!"; + java.util.HashMap map51005 = new java.util.HashMap(); + map51005.put("keyA-51005", "a_Value"); // put some stuff in the collection + map51005.put("keyB-51005", param); // put it in a collection + map51005.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map51005.get("keyB-51005"); // get it back out + bar = (String) map51005.get("keyA-51005"); // get safe value back out + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + org.w3c.dom.NodeList nodeList = + (org.w3c.dom.NodeList) + xp.compile(expression) + .evaluate(xmlDocument, javax.xml.xpath.XPathConstants.NODESET); + + response.getWriter().println("Your query results are:
"); + + for (int i = 0; i < nodeList.getLength(); i++) { + org.w3c.dom.Element value = (org.w3c.dom.Element) nodeList.item(i); + response.getWriter().println(value.getTextContent() + "
"); + } + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00117.java b/OWASP DATASET/BenchmarkTest00117.java new file mode 100644 index 0000000000000000000000000000000000000000..9829ccc8a143bc7aeae963d225db10ff42b3db9b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00117.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest00117") +public class BenchmarkTest00117 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00117", "2222"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/xpathi-00/BenchmarkTest00117.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00117")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + org.w3c.dom.NodeList nodeList = + (org.w3c.dom.NodeList) + xp.compile(expression) + .evaluate(xmlDocument, javax.xml.xpath.XPathConstants.NODESET); + + response.getWriter().println("Your query results are:
"); + + for (int i = 0; i < nodeList.getLength(); i++) { + org.w3c.dom.Element value = (org.w3c.dom.Element) nodeList.item(i); + response.getWriter().println(value.getTextContent() + "
"); + } + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00118.java b/OWASP DATASET/BenchmarkTest00118.java new file mode 100644 index 0000000000000000000000000000000000000000..c768c2a1c85d86647503995eedb376e6a22840a1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00118.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest00118") +public class BenchmarkTest00118 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00118", "2222"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/xpathi-00/BenchmarkTest00118.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00118")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + String result = xp.evaluate(expression, xmlDocument); + + response.getWriter().println("Your query results are: " + result + "
"); + + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00119.java b/OWASP DATASET/BenchmarkTest00119.java new file mode 100644 index 0000000000000000000000000000000000000000..ad33562eebfc7712b1c2d68ed198ff4f4d527850 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00119.java @@ -0,0 +1,173 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00119") +public class BenchmarkTest00119 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00119") != null) { + param = request.getHeader("BenchmarkTest00119"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + // Chain a bunch of propagators in sequence + String a8142 = param; // assign + StringBuilder b8142 = new StringBuilder(a8142); // stick in stringbuilder + b8142.append(" SafeStuff"); // append some safe content + b8142.replace( + b8142.length() - "Chars".length(), + b8142.length(), + "Chars"); // replace some of the end content + java.util.HashMap map8142 = new java.util.HashMap(); + map8142.put("key8142", b8142.toString()); // put in a collection + String c8142 = (String) map8142.get("key8142"); // get it back out + String d8142 = c8142.substring(0, c8142.length() - 1); // extract most of it + String e8142 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d8142.getBytes()))); // B64 encode and decode it + String f8142 = e8142.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f8142); // reflection + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "DES/CBC/PKCS5PADDING", java.security.Security.getProvider("SunJCE")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00120.java b/OWASP DATASET/BenchmarkTest00120.java new file mode 100644 index 0000000000000000000000000000000000000000..893bb42d2a5ee93364d44bacfc66d930d6457c7c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00120.java @@ -0,0 +1,157 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00120") +public class BenchmarkTest00120 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00120") != null) { + param = request.getHeader("BenchmarkTest00120"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz43804 = new StringBuilder(param); + bar = sbxyz43804.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "DES/CBC/PKCS5PADDING", java.security.Security.getProvider("SunJCE")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00121.java b/OWASP DATASET/BenchmarkTest00121.java new file mode 100644 index 0000000000000000000000000000000000000000..eeac03e8a92046642844eabe5ebc1461d09fd158 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00121.java @@ -0,0 +1,164 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00121") +public class BenchmarkTest00121 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00121") != null) { + param = request.getHeader("BenchmarkTest00121"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00122.java b/OWASP DATASET/BenchmarkTest00122.java new file mode 100644 index 0000000000000000000000000000000000000000..9dc618f3d6bf6050d9f2b91d0bf109a9adc0c8a3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00122.java @@ -0,0 +1,154 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00122") +public class BenchmarkTest00122 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00122") != null) { + param = request.getHeader("BenchmarkTest00122"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = param; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00123.java b/OWASP DATASET/BenchmarkTest00123.java new file mode 100644 index 0000000000000000000000000000000000000000..2869e95dd7c4f48807062794c3c30c61a2d0219e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00123.java @@ -0,0 +1,123 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00123") +public class BenchmarkTest00123 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00123") != null) { + param = request.getHeader("BenchmarkTest00123"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00124.java b/OWASP DATASET/BenchmarkTest00124.java new file mode 100644 index 0000000000000000000000000000000000000000..d896eccdba374491e157a20b4b64baa625f2aa58 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00124.java @@ -0,0 +1,128 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00124") +public class BenchmarkTest00124 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00124") != null) { + param = request.getHeader("BenchmarkTest00124"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00125.java b/OWASP DATASET/BenchmarkTest00125.java new file mode 100644 index 0000000000000000000000000000000000000000..f7e36690aeee8d18b41ae79a0daace5d0582f3c7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00125.java @@ -0,0 +1,123 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00125") +public class BenchmarkTest00125 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00125") != null) { + param = request.getHeader("BenchmarkTest00125"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00126.java b/OWASP DATASET/BenchmarkTest00126.java new file mode 100644 index 0000000000000000000000000000000000000000..90b106024c4aa30b70844c2039b0b3258d7d8dd6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00126.java @@ -0,0 +1,125 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00126") +public class BenchmarkTest00126 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00126") != null) { + param = request.getHeader("BenchmarkTest00126"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "AES/CCM/NoPadding", java.security.Security.getProvider("BC")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00127.java b/OWASP DATASET/BenchmarkTest00127.java new file mode 100644 index 0000000000000000000000000000000000000000..5192eaf3f00e463ad3ac7f1f8a463c3e0baca757 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00127.java @@ -0,0 +1,134 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00127") +public class BenchmarkTest00127 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00127") != null) { + param = request.getHeader("BenchmarkTest00127"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + // java.security.SecureRandom random = new java.security.SecureRandom(); + // byte[] iv = random.generateSeed(16); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg2", "AES/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00128.java b/OWASP DATASET/BenchmarkTest00128.java new file mode 100644 index 0000000000000000000000000000000000000000..0a8d0a3a0cc58f23fc5f6fd9a24cacb6c72767b6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00128.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00128") +public class BenchmarkTest00128 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00128") != null) { + param = request.getHeader("BenchmarkTest00128"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + // java.security.SecureRandom random = new java.security.SecureRandom(); + // byte[] iv = random.generateSeed(16); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg2", "AES/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00129.java b/OWASP DATASET/BenchmarkTest00129.java new file mode 100644 index 0000000000000000000000000000000000000000..f3d4766958bdd757c8b1ad7d5c76d09bfc815244 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00129.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00129") +public class BenchmarkTest00129 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00129") != null) { + param = request.getHeader("BenchmarkTest00129"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + // java.security.SecureRandom random = new java.security.SecureRandom(); + // byte[] iv = random.generateSeed(16); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg2", "AES/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00130.java b/OWASP DATASET/BenchmarkTest00130.java new file mode 100644 index 0000000000000000000000000000000000000000..d9013fb9bd096933dc77807dab99f8fec4480fd8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00130.java @@ -0,0 +1,143 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00130") +public class BenchmarkTest00130 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00130") != null) { + param = request.getHeader("BenchmarkTest00130"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + // java.security.SecureRandom random = new java.security.SecureRandom(); + // byte[] iv = random.generateSeed(16); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg2", "AES/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00131.java b/OWASP DATASET/BenchmarkTest00131.java new file mode 100644 index 0000000000000000000000000000000000000000..1ff9951b9dad1eb812472107985a5494770029bb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00131.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00131") +public class BenchmarkTest00131 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00131") != null) { + param = request.getHeader("BenchmarkTest00131"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + java.io.File fileTarget = new java.io.File(bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00132.java b/OWASP DATASET/BenchmarkTest00132.java new file mode 100644 index 0000000000000000000000000000000000000000..1137f02bcfede421f4ef02ef9acda277426674ed --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00132.java @@ -0,0 +1,111 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00132") +public class BenchmarkTest00132 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00132") != null) { + param = request.getHeader("BenchmarkTest00132"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(new java.io.File(fileName)); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting FileInputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00133.java b/OWASP DATASET/BenchmarkTest00133.java new file mode 100644 index 0000000000000000000000000000000000000000..4a280986b6cb384a1158c1ea83d8dffaf0f42aeb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00133.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00133") +public class BenchmarkTest00133 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00133") != null) { + param = request.getHeader("BenchmarkTest00133"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(fileName); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00134.java b/OWASP DATASET/BenchmarkTest00134.java new file mode 100644 index 0000000000000000000000000000000000000000..f6ef36539ebb05fcaa0fa2ee39d32b2776322a1c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00134.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00134") +public class BenchmarkTest00134 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00134") != null) { + param = request.getHeader("BenchmarkTest00134"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + try ( + // Create the file first so the test won't throw an exception if it doesn't exist. + // Note: Don't actually do this because this method signature could cause a tool to find + // THIS file constructor + // as a vuln, rather than the File signature we are trying to actually test. + // If necessary, just run the benchmark twice. The 1st run should create all the necessary + // files. + // new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar).createNewFile(); + + java.io.FileOutputStream fos = + new java.io.FileOutputStream(new java.io.FileInputStream(fileName).getFD()); ) { + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00135.java b/OWASP DATASET/BenchmarkTest00135.java new file mode 100644 index 0000000000000000000000000000000000000000..706d601c62c39e9ba186eb603c3e42931f682d1d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00135.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00135") +public class BenchmarkTest00135 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00135") != null) { + param = request.getHeader("BenchmarkTest00135"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + try ( + // Create the file first so the test won't throw an exception if it doesn't exist. + // Note: Don't actually do this because this method signature could cause a tool to find + // THIS file constructor + // as a vuln, rather than the File signature we are trying to actually test. + // If necessary, just run the benchmark twice. The 1st run should create all the necessary + // files. + // new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar).createNewFile(); + + java.io.FileOutputStream fos = + new java.io.FileOutputStream(new java.io.FileInputStream(fileName).getFD()); ) { + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00136.java b/OWASP DATASET/BenchmarkTest00136.java new file mode 100644 index 0000000000000000000000000000000000000000..7c0dccfd42479b789a1d8292404479600fa389d6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00136.java @@ -0,0 +1,98 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00136") +public class BenchmarkTest00136 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00136") != null) { + param = request.getHeader("BenchmarkTest00136"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName, false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00137.java b/OWASP DATASET/BenchmarkTest00137.java new file mode 100644 index 0000000000000000000000000000000000000000..b9e3febf72501d9a9af867b50c53673f0f843d17 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00137.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00137") +public class BenchmarkTest00137 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00137") != null) { + param = request.getHeader("BenchmarkTest00137"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "safe!"; + java.util.HashMap map53289 = new java.util.HashMap(); + map53289.put("keyA-53289", "a_Value"); // put some stuff in the collection + map53289.put("keyB-53289", param); // put it in a collection + map53289.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map53289.get("keyB-53289"); // get it back out + bar = (String) map53289.get("keyA-53289"); // get safe value back out + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + java.io.InputStream is = null; + + try { + java.nio.file.Path path = java.nio.file.Paths.get(fileName); + is = java.nio.file.Files.newInputStream(path, java.nio.file.StandardOpenOption.READ); + byte[] b = new byte[1000]; + int size = is.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + is.close(); + } catch (Exception e) { + System.out.println("Couldn't open InputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting InputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (is != null) { + try { + is.close(); + is = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00138.java b/OWASP DATASET/BenchmarkTest00138.java new file mode 100644 index 0000000000000000000000000000000000000000..04d28e6ef7d11fc6f74f2bafe8c496f2fd15dee4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00138.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest00138") +public class BenchmarkTest00138 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00138") != null) { + param = request.getHeader("BenchmarkTest00138"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + bar + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + + javax.naming.directory.DirContext ctx = ads.getDirContext(); + javax.naming.directory.InitialDirContext idc = + (javax.naming.directory.InitialDirContext) ctx; + boolean found = false; + javax.naming.NamingEnumeration results = + idc.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00139.java b/OWASP DATASET/BenchmarkTest00139.java new file mode 100644 index 0000000000000000000000000000000000000000..06f78927f91122ad79b205bb68e55c54de7149ba --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00139.java @@ -0,0 +1,126 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest00139") +public class BenchmarkTest00139 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00139") != null) { + param = request.getHeader("BenchmarkTest00139"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + // Chain a bunch of propagators in sequence + String a48394 = param; // assign + StringBuilder b48394 = new StringBuilder(a48394); // stick in stringbuilder + b48394.append(" SafeStuff"); // append some safe content + b48394.replace( + b48394.length() - "Chars".length(), + b48394.length(), + "Chars"); // replace some of the end content + java.util.HashMap map48394 = new java.util.HashMap(); + map48394.put("key48394", b48394.toString()); // put in a collection + String c48394 = (String) map48394.get("key48394"); // get it back out + String d48394 = c48394.substring(0, c48394.length() - 1); // extract most of it + String e48394 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d48394.getBytes()))); // B64 encode and decode it + String f48394 = e48394.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g48394 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g48394); // reflection + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person)(uid=" + bar + "))"; + + javax.naming.directory.DirContext ctx = ads.getDirContext(); + javax.naming.directory.InitialDirContext idc = + (javax.naming.directory.InitialDirContext) ctx; + boolean found = false; + javax.naming.NamingEnumeration results = + idc.search(base, filter, sc); + + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00140.java b/OWASP DATASET/BenchmarkTest00140.java new file mode 100644 index 0000000000000000000000000000000000000000..31b9bdc4c7decdc8f2cc7ec27c74eac1ab7e7607 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00140.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00140") +public class BenchmarkTest00140 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00140") != null) { + param = request.getHeader("BenchmarkTest00140"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + double value = java.lang.Math.random(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Doug"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + response.getWriter().println("Weak Randomness Test java.lang.Math.random() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00141.java b/OWASP DATASET/BenchmarkTest00141.java new file mode 100644 index 0000000000000000000000000000000000000000..b6bb3d4d83117561d86d9bbef1d9c78b4bc22b26 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00141.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00141") +public class BenchmarkTest00141 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00141") != null) { + param = request.getHeader("BenchmarkTest00141"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("SHA1", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00142.java b/OWASP DATASET/BenchmarkTest00142.java new file mode 100644 index 0000000000000000000000000000000000000000..61e88c935dbcab096a5bc46ae25ac25207ec4e9c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00142.java @@ -0,0 +1,107 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00142") +public class BenchmarkTest00142 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00142") != null) { + param = request.getHeader("BenchmarkTest00142"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-256"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00143.java b/OWASP DATASET/BenchmarkTest00143.java new file mode 100644 index 0000000000000000000000000000000000000000..d20c36d262e339729e8c59d0b9a056db0c230fee --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00143.java @@ -0,0 +1,125 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00143") +public class BenchmarkTest00143 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00143") != null) { + param = request.getHeader("BenchmarkTest00143"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00144.java b/OWASP DATASET/BenchmarkTest00144.java new file mode 100644 index 0000000000000000000000000000000000000000..4638da678c6203b6b86c39ce35a1e12c651fc4aa --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00144.java @@ -0,0 +1,67 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00144") +public class BenchmarkTest00144 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(java.util.Locale.US, bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00145.java b/OWASP DATASET/BenchmarkTest00145.java new file mode 100644 index 0000000000000000000000000000000000000000..15129f4b018a2dc6aa2fd61c18199d52d18a83f8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00145.java @@ -0,0 +1,62 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00145") +public class BenchmarkTest00145 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "safe!"; + java.util.HashMap map17589 = new java.util.HashMap(); + map17589.put("keyA-17589", "a-Value"); // put some stuff in the collection + map17589.put("keyB-17589", param); // put it in a collection + map17589.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map17589.get("keyB-17589"); // get it back out + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(java.util.Locale.US, bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00146.java b/OWASP DATASET/BenchmarkTest00146.java new file mode 100644 index 0000000000000000000000000000000000000000..30ccd6d74f0c76b679ae377db3dc48ad2992712e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00146.java @@ -0,0 +1,61 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00146") +public class BenchmarkTest00146 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz67327 = new StringBuilder(param); + bar = sbxyz67327.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(java.util.Locale.US, bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00147.java b/OWASP DATASET/BenchmarkTest00147.java new file mode 100644 index 0000000000000000000000000000000000000000..f714badb2c2fb86f93c7b36e7bc04d4c3c5d5893 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00147.java @@ -0,0 +1,67 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00147") +public class BenchmarkTest00147 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().format("Formatted like: %1$s and %2$s.", obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00148.java b/OWASP DATASET/BenchmarkTest00148.java new file mode 100644 index 0000000000000000000000000000000000000000..368d66c5c86dbf0e932e9f01aab072d7d28681ca --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00148.java @@ -0,0 +1,62 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00148") +public class BenchmarkTest00148 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().format("Formatted like: %1$s and %2$s.", obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00149.java b/OWASP DATASET/BenchmarkTest00149.java new file mode 100644 index 0000000000000000000000000000000000000000..329650dc1dfc45e2ee42739f7d43ddf3a5d79e4c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00149.java @@ -0,0 +1,58 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00149") +public class BenchmarkTest00149 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + StringBuilder sbxyz19132 = new StringBuilder(param); + String bar = sbxyz19132.append("_SafeStuff").toString(); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00150.java b/OWASP DATASET/BenchmarkTest00150.java new file mode 100644 index 0000000000000000000000000000000000000000..39baf141418fc51551b17a14bb08a8728edd53f9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00150.java @@ -0,0 +1,62 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00150") +public class BenchmarkTest00150 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00151.java b/OWASP DATASET/BenchmarkTest00151.java new file mode 100644 index 0000000000000000000000000000000000000000..e530e70eb59522d473953f23d4fe7b23ca2b7e6f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00151.java @@ -0,0 +1,67 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00151") +public class BenchmarkTest00151 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00152.java b/OWASP DATASET/BenchmarkTest00152.java new file mode 100644 index 0000000000000000000000000000000000000000..905919555a9312ea5a79fb25cf9b5fa2d3638a24 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00152.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00152") +public class BenchmarkTest00152 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar.toCharArray()); + } +} diff --git a/OWASP DATASET/BenchmarkTest00153.java b/OWASP DATASET/BenchmarkTest00153.java new file mode 100644 index 0000000000000000000000000000000000000000..84410887a0f7be1d463c8bb78c1cda7a3d6c2930 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00153.java @@ -0,0 +1,61 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00153") +public class BenchmarkTest00153 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "safe!"; + java.util.HashMap map96050 = new java.util.HashMap(); + map96050.put("keyA-96050", "a-Value"); // put some stuff in the collection + map96050.put("keyB-96050", param); // put it in a collection + map96050.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map96050.get("keyB-96050"); // get it back out + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00154.java b/OWASP DATASET/BenchmarkTest00154.java new file mode 100644 index 0000000000000000000000000000000000000000..577a0f341e2c0aa88563191696a29f4d908e8f53 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00154.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00154") +public class BenchmarkTest00154 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00155.java b/OWASP DATASET/BenchmarkTest00155.java new file mode 100644 index 0000000000000000000000000000000000000000..f709a012d57ec649370bf001e9ff8888c6488d60 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00155.java @@ -0,0 +1,58 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00155") +public class BenchmarkTest00155 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00156.java b/OWASP DATASET/BenchmarkTest00156.java new file mode 100644 index 0000000000000000000000000000000000000000..d6b2b741fc1899cdef8912c3fc3d652326738b51 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00156.java @@ -0,0 +1,66 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00156") +public class BenchmarkTest00156 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar.toCharArray()); + } +} diff --git a/OWASP DATASET/BenchmarkTest00157.java b/OWASP DATASET/BenchmarkTest00157.java new file mode 100644 index 0000000000000000000000000000000000000000..cb0f518c06a921df3460e27d0e61ef57ac3b7ec6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00157.java @@ -0,0 +1,61 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00157") +public class BenchmarkTest00157 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00158.java b/OWASP DATASET/BenchmarkTest00158.java new file mode 100644 index 0000000000000000000000000000000000000000..bf3f04011f29f27cf058da76240a08861a508bcb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00158.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00158") +public class BenchmarkTest00158 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00158") != null) { + param = request.getHeader("BenchmarkTest00158"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00159.java b/OWASP DATASET/BenchmarkTest00159.java new file mode 100644 index 0000000000000000000000000000000000000000..03c1660b58c3f16a87ff54114498af76239e974e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00159.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00159") +public class BenchmarkTest00159 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00159") != null) { + param = request.getHeader("BenchmarkTest00159"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + String a1 = ""; + String a2 = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + } else { + a1 = "sh"; + a2 = "-c"; + } + String[] args = {a1, a2, "echo " + bar}; + + ProcessBuilder pb = new ProcessBuilder(args); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.lang.String[]) Test Case"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00160.java b/OWASP DATASET/BenchmarkTest00160.java new file mode 100644 index 0000000000000000000000000000000000000000..0d667252d6cf0234f0c520e4fb4b70a1c8f72dad --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00160.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00160") +public class BenchmarkTest00160 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00160") != null) { + param = request.getHeader("BenchmarkTest00160"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + byte[] bytes = new byte[10]; + new java.util.Random().nextBytes(bytes); + String rememberMeKey = org.owasp.esapi.ESAPI.encoder().encodeForBase64(bytes, true); + + String user = "Byron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextBytes() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00161.java b/OWASP DATASET/BenchmarkTest00161.java new file mode 100644 index 0000000000000000000000000000000000000000..eb6b25098cb4309a851114ff7d367b87f5600ba7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00161.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00161") +public class BenchmarkTest00161 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00161") != null) { + param = request.getHeader("BenchmarkTest00161"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "safe!"; + java.util.HashMap map91760 = new java.util.HashMap(); + map91760.put("keyA-91760", "a_Value"); // put some stuff in the collection + map91760.put("keyB-91760", param); // put it in a collection + map91760.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map91760.get("keyB-91760"); // get it back out + bar = (String) map91760.get("keyA-91760"); // get safe value back out + + double value = new java.util.Random().nextDouble(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Donna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextDouble() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00162.java b/OWASP DATASET/BenchmarkTest00162.java new file mode 100644 index 0000000000000000000000000000000000000000..8ee8b4d1b528385067839447510b624d336f0c8b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00162.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00162") +public class BenchmarkTest00162 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00162") != null) { + param = request.getHeader("BenchmarkTest00162"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + double stuff = new java.util.Random().nextGaussian(); + String rememberMeKey = Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "Gayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter() + .println("Weak Randomness Test java.util.Random.nextGaussian() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00163.java b/OWASP DATASET/BenchmarkTest00163.java new file mode 100644 index 0000000000000000000000000000000000000000..8df34551ec23cc864b45016ee89b1578ecfac5e3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00163.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00163") +public class BenchmarkTest00163 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00163") != null) { + param = request.getHeader("BenchmarkTest00163"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + StringBuilder sbxyz89305 = new StringBuilder(param); + String bar = sbxyz89305.append("_SafeStuff").toString(); + + double stuff = new java.util.Random().nextGaussian(); + String rememberMeKey = Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "Gayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter() + .println("Weak Randomness Test java.util.Random.nextGaussian() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00164.java b/OWASP DATASET/BenchmarkTest00164.java new file mode 100644 index 0000000000000000000000000000000000000000..79ff234e0c7a94d08c1f604acf12181386d9d760 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00164.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00164") +public class BenchmarkTest00164 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00164") != null) { + param = request.getHeader("BenchmarkTest00164"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00165.java b/OWASP DATASET/BenchmarkTest00165.java new file mode 100644 index 0000000000000000000000000000000000000000..94a570566c4359b2af703ffad6930e8915557661 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00165.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00165") +public class BenchmarkTest00165 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00165") != null) { + param = request.getHeader("BenchmarkTest00165"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00166.java b/OWASP DATASET/BenchmarkTest00166.java new file mode 100644 index 0000000000000000000000000000000000000000..45bc5f4e384a7637cb229fb64128c24760735060 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00166.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00166") +public class BenchmarkTest00166 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00166") != null) { + param = request.getHeader("BenchmarkTest00166"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = param; + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00167.java b/OWASP DATASET/BenchmarkTest00167.java new file mode 100644 index 0000000000000000000000000000000000000000..a9428f90a3b3a35c277d51b17b7369da6f2d25e6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00167.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00167") +public class BenchmarkTest00167 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00167") != null) { + param = request.getHeader("BenchmarkTest00167"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00168.java b/OWASP DATASET/BenchmarkTest00168.java new file mode 100644 index 0000000000000000000000000000000000000000..82d00266d6a09f701799d5d6893b01a2addc6d7e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00168.java @@ -0,0 +1,107 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00168") +public class BenchmarkTest00168 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00168") != null) { + param = request.getHeader("BenchmarkTest00168"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00169.java b/OWASP DATASET/BenchmarkTest00169.java new file mode 100644 index 0000000000000000000000000000000000000000..4a05d35b12ba11572342b99b06fb84bd84ed524a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00169.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest00169") +public class BenchmarkTest00169 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00169") != null) { + param = request.getHeader("BenchmarkTest00169"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00170.java b/OWASP DATASET/BenchmarkTest00170.java new file mode 100644 index 0000000000000000000000000000000000000000..6a6cc55b40db3c60030a22dab3e4a5b327afb393 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00170.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest00170") +public class BenchmarkTest00170 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00170") != null) { + param = request.getHeader("BenchmarkTest00170"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + // Chain a bunch of propagators in sequence + String a9823 = param; // assign + StringBuilder b9823 = new StringBuilder(a9823); // stick in stringbuilder + b9823.append(" SafeStuff"); // append some safe content + b9823.replace( + b9823.length() - "Chars".length(), + b9823.length(), + "Chars"); // replace some of the end content + java.util.HashMap map9823 = new java.util.HashMap(); + map9823.put("key9823", b9823.toString()); // put in a collection + String c9823 = (String) map9823.get("key9823"); // get it back out + String d9823 = c9823.substring(0, c9823.length() - 1); // extract most of it + String e9823 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d9823.getBytes()))); // B64 encode and decode it + String f9823 = e9823.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g9823 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g9823); // reflection + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00171.java b/OWASP DATASET/BenchmarkTest00171.java new file mode 100644 index 0000000000000000000000000000000000000000..fe7d47dd20fe2c2c94b05c5ac47250b54c9f396c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00171.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00171") +public class BenchmarkTest00171 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00171") != null) { + param = request.getHeader("BenchmarkTest00171"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "safe!"; + java.util.HashMap map40534 = new java.util.HashMap(); + map40534.put("keyA-40534", "a_Value"); // put some stuff in the collection + map40534.put("keyB-40534", param); // put it in a collection + map40534.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map40534.get("keyB-40534"); // get it back out + bar = (String) map40534.get("keyA-40534"); // get safe value back out + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00172.java b/OWASP DATASET/BenchmarkTest00172.java new file mode 100644 index 0000000000000000000000000000000000000000..847470f24adf582f5eba85a9a4c32d355711c6e1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00172.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00172") +public class BenchmarkTest00172 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00172") != null) { + param = request.getHeader("BenchmarkTest00172"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "safe!"; + java.util.HashMap map59408 = new java.util.HashMap(); + map59408.put("keyA-59408", "a-Value"); // put some stuff in the collection + map59408.put("keyB-59408", param); // put it in a collection + map59408.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map59408.get("keyB-59408"); // get it back out + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00173.java b/OWASP DATASET/BenchmarkTest00173.java new file mode 100644 index 0000000000000000000000000000000000000000..4a195b927bac0c3cd9bb47f7ca8c85da2da1a7f9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00173.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00173") +public class BenchmarkTest00173 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00173") != null) { + param = request.getHeader("BenchmarkTest00173"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "safe!"; + java.util.HashMap map68097 = new java.util.HashMap(); + map68097.put("keyA-68097", "a-Value"); // put some stuff in the collection + map68097.put("keyB-68097", param); // put it in a collection + map68097.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map68097.get("keyB-68097"); // get it back out + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00174.java b/OWASP DATASET/BenchmarkTest00174.java new file mode 100644 index 0000000000000000000000000000000000000000..f086b7cb574bc150e217dbf457926532af8a25a1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00174.java @@ -0,0 +1,72 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00174") +public class BenchmarkTest00174 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00174") != null) { + param = request.getHeader("BenchmarkTest00174"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00175.java b/OWASP DATASET/BenchmarkTest00175.java new file mode 100644 index 0000000000000000000000000000000000000000..5bcda084605db96e0118e81e6144a6b55d85c43a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00175.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00175") +public class BenchmarkTest00175 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00175") != null) { + param = request.getHeader("BenchmarkTest00175"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "safe!"; + java.util.HashMap map50591 = new java.util.HashMap(); + map50591.put("keyA-50591", "a_Value"); // put some stuff in the collection + map50591.put("keyB-50591", param); // put it in a collection + map50591.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map50591.get("keyB-50591"); // get it back out + bar = (String) map50591.get("keyA-50591"); // get safe value back out + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00176.java b/OWASP DATASET/BenchmarkTest00176.java new file mode 100644 index 0000000000000000000000000000000000000000..0a6916f3e6288e0c2c10fd7b49d6f9608f0dabb7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00176.java @@ -0,0 +1,73 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00176") +public class BenchmarkTest00176 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00176") != null) { + param = request.getHeader("BenchmarkTest00176"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = param; + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = + r.exec(cmd + bar, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00177.java b/OWASP DATASET/BenchmarkTest00177.java new file mode 100644 index 0000000000000000000000000000000000000000..f5b663ce6faeeac8eed45895c0b572dbe60d3c19 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00177.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00177") +public class BenchmarkTest00177 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00177") != null) { + param = request.getHeader("BenchmarkTest00177"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = + r.exec(cmd + bar, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00178.java b/OWASP DATASET/BenchmarkTest00178.java new file mode 100644 index 0000000000000000000000000000000000000000..1463e976c3abc89ff2e1b8b831a6aa2de79b5daa --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00178.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00178") +public class BenchmarkTest00178 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00178") != null) { + param = request.getHeader("BenchmarkTest00178"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + getNextNumber(numGen, randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeBystander"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } + + void getNextNumber(java.util.Random generator, byte[] barray) { + generator.nextBytes(barray); + } +} diff --git a/OWASP DATASET/BenchmarkTest00179.java b/OWASP DATASET/BenchmarkTest00179.java new file mode 100644 index 0000000000000000000000000000000000000000..32bfc396d695f8fd12320e97d0d6da93012a3db5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00179.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00179") +public class BenchmarkTest00179 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00179") != null) { + param = request.getHeader("BenchmarkTest00179"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00180.java b/OWASP DATASET/BenchmarkTest00180.java new file mode 100644 index 0000000000000000000000000000000000000000..5766f679d1687b572a47cc2e5fd89433caab4091 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00180.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00180") +public class BenchmarkTest00180 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00180") != null) { + param = request.getHeader("BenchmarkTest00180"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + double rand = getNextNumber(numGen); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonatella"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } + + double getNextNumber(java.util.Random generator) { + return generator.nextDouble(); + } +} diff --git a/OWASP DATASET/BenchmarkTest00181.java b/OWASP DATASET/BenchmarkTest00181.java new file mode 100644 index 0000000000000000000000000000000000000000..1e8ab75c4bcc6067df5745ef658a86d741f6e1fe --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00181.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00181") +public class BenchmarkTest00181 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00181") != null) { + param = request.getHeader("BenchmarkTest00181"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00182.java b/OWASP DATASET/BenchmarkTest00182.java new file mode 100644 index 0000000000000000000000000000000000000000..4106cc18b0d63f42c1ba30032630910c45ad83c7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00182.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00182") +public class BenchmarkTest00182 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00182") != null) { + param = request.getHeader("BenchmarkTest00182"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + // Chain a bunch of propagators in sequence + String a48649 = param; // assign + StringBuilder b48649 = new StringBuilder(a48649); // stick in stringbuilder + b48649.append(" SafeStuff"); // append some safe content + b48649.replace( + b48649.length() - "Chars".length(), + b48649.length(), + "Chars"); // replace some of the end content + java.util.HashMap map48649 = new java.util.HashMap(); + map48649.put("key48649", b48649.toString()); // put in a collection + String c48649 = (String) map48649.get("key48649"); // get it back out + String d48649 = c48649.substring(0, c48649.length() - 1); // extract most of it + String e48649 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d48649.getBytes()))); // B64 encode and decode it + String f48649 = e48649.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g48649 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g48649); // reflection + + try { + double stuff = java.security.SecureRandom.getInstance("SHA1PRNG").nextGaussian(); + String rememberMeKey = + Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "SafeGayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextGaussian() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextGaussian() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00183.java b/OWASP DATASET/BenchmarkTest00183.java new file mode 100644 index 0000000000000000000000000000000000000000..03ea2fa671240845982beeb2e80c5c166503a5ea --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00183.java @@ -0,0 +1,127 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00183") +public class BenchmarkTest00183 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00183") != null) { + param = request.getHeader("BenchmarkTest00183"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + try { + double stuff = java.security.SecureRandom.getInstance("SHA1PRNG").nextGaussian(); + String rememberMeKey = + Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "SafeGayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextGaussian() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextGaussian() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00184.java b/OWASP DATASET/BenchmarkTest00184.java new file mode 100644 index 0000000000000000000000000000000000000000..b4a000b8c6a000d78cf2f936b9959266336a40b5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00184.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00184") +public class BenchmarkTest00184 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00184") != null) { + param = request.getHeader("BenchmarkTest00184"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "safe!"; + java.util.HashMap map46743 = new java.util.HashMap(); + map46743.put("keyA-46743", "a-Value"); // put some stuff in the collection + map46743.put("keyB-46743", param); // put it in a collection + map46743.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map46743.get("keyB-46743"); // get it back out + + try { + int randNumber = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "SafeInga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt(int) - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt(int) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00185.java b/OWASP DATASET/BenchmarkTest00185.java new file mode 100644 index 0000000000000000000000000000000000000000..5857f480c1f8d30bdf7dda6464f85a50576f645b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00185.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00185") +public class BenchmarkTest00185 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00185") != null) { + param = request.getHeader("BenchmarkTest00185"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "safe!"; + java.util.HashMap map60659 = new java.util.HashMap(); + map60659.put("keyA-60659", "a_Value"); // put some stuff in the collection + map60659.put("keyB-60659", param); // put it in a collection + map60659.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map60659.get("keyB-60659"); // get it back out + bar = (String) map60659.get("keyA-60659"); // get safe value back out + + try { + int randNumber = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "SafeInga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt(int) - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt(int) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00186.java b/OWASP DATASET/BenchmarkTest00186.java new file mode 100644 index 0000000000000000000000000000000000000000..fd833585dc0badf35070972a13f91a99e54232c4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00186.java @@ -0,0 +1,128 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00186") +public class BenchmarkTest00186 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00186") != null) { + param = request.getHeader("BenchmarkTest00186"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + // Chain a bunch of propagators in sequence + String a18509 = param; // assign + StringBuilder b18509 = new StringBuilder(a18509); // stick in stringbuilder + b18509.append(" SafeStuff"); // append some safe content + b18509.replace( + b18509.length() - "Chars".length(), + b18509.length(), + "Chars"); // replace some of the end content + java.util.HashMap map18509 = new java.util.HashMap(); + map18509.put("key18509", b18509.toString()); // put in a collection + String c18509 = (String) map18509.get("key18509"); // get it back out + String d18509 = c18509.substring(0, c18509.length() - 1); // extract most of it + String e18509 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d18509.getBytes()))); // B64 encode and decode it + String f18509 = e18509.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g18509 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g18509); // reflection + + try { + int randNumber = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "SafeInga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt(int) - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt(int) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00187.java b/OWASP DATASET/BenchmarkTest00187.java new file mode 100644 index 0000000000000000000000000000000000000000..84603b9b741b37869b4b95ae0f4f727349fd69c7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00187.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00187") +public class BenchmarkTest00187 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00187") != null) { + param = request.getHeader("BenchmarkTest00187"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + try { + int r = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "SafeIngrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00188.java b/OWASP DATASET/BenchmarkTest00188.java new file mode 100644 index 0000000000000000000000000000000000000000..022c204b3441c02a128bc546decb84c358b2cb9e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00188.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00188") +public class BenchmarkTest00188 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00188") != null) { + param = request.getHeader("BenchmarkTest00188"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + try { + long l = java.security.SecureRandom.getInstance("SHA1PRNG").nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "SafeLogan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextLong() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextLong() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00189.java b/OWASP DATASET/BenchmarkTest00189.java new file mode 100644 index 0000000000000000000000000000000000000000..74f43ee145fa9da28cbfae5bcbdca102eb71b510 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00189.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00189") +public class BenchmarkTest00189 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00189") != null) { + param = request.getHeader("BenchmarkTest00189"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + // Chain a bunch of propagators in sequence + String a14330 = param; // assign + StringBuilder b14330 = new StringBuilder(a14330); // stick in stringbuilder + b14330.append(" SafeStuff"); // append some safe content + b14330.replace( + b14330.length() - "Chars".length(), + b14330.length(), + "Chars"); // replace some of the end content + java.util.HashMap map14330 = new java.util.HashMap(); + map14330.put("key14330", b14330.toString()); // put in a collection + String c14330 = (String) map14330.get("key14330"); // get it back out + String d14330 = c14330.substring(0, c14330.length() - 1); // extract most of it + String e14330 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d14330.getBytes()))); // B64 encode and decode it + String f14330 = e14330.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g14330 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g14330); // reflection + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00190.java b/OWASP DATASET/BenchmarkTest00190.java new file mode 100644 index 0000000000000000000000000000000000000000..a30e0c9b4adb5e5ae13b6bf8e86d86ecb9186657 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00190.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00190") +public class BenchmarkTest00190 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00190") != null) { + param = request.getHeader("BenchmarkTest00190"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00191.java b/OWASP DATASET/BenchmarkTest00191.java new file mode 100644 index 0000000000000000000000000000000000000000..9be0c09e500a5fd661329f9748dfa8514d4b0f10 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00191.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00191") +public class BenchmarkTest00191 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00191") != null) { + param = request.getHeader("BenchmarkTest00191"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00192.java b/OWASP DATASET/BenchmarkTest00192.java new file mode 100644 index 0000000000000000000000000000000000000000..605094f65b00d31a85e81e976c96648d7c7d62b0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00192.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00192") +public class BenchmarkTest00192 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00192") != null) { + param = request.getHeader("BenchmarkTest00192"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = connection.prepareStatement(sql); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00193.java b/OWASP DATASET/BenchmarkTest00193.java new file mode 100644 index 0000000000000000000000000000000000000000..f8930ef5168af19f0fc75b7fd6ae10e74f411f0c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00193.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00193") +public class BenchmarkTest00193 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00193") != null) { + param = request.getHeader("BenchmarkTest00193"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, new String[] {"Column1", "Column2"}); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00194.java b/OWASP DATASET/BenchmarkTest00194.java new file mode 100644 index 0000000000000000000000000000000000000000..a80f08636b7b5d5a9344bcfdb15c082b23f9503b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00194.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00194") +public class BenchmarkTest00194 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00194") != null) { + param = request.getHeader("BenchmarkTest00194"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + // System.out.println("no results for query: " + sql + " because the Spring batchUpdate + // method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00195.java b/OWASP DATASET/BenchmarkTest00195.java new file mode 100644 index 0000000000000000000000000000000000000000..c986f56838d643050ff56df81e4e123673b314e4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00195.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00195") +public class BenchmarkTest00195 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00195") != null) { + param = request.getHeader("BenchmarkTest00195"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.execute(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring execute method doesn't return results."); + + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00196.java b/OWASP DATASET/BenchmarkTest00196.java new file mode 100644 index 0000000000000000000000000000000000000000..77a8276aedfb6624c4c2790bfe2816e7e058cff2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00196.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00196") +public class BenchmarkTest00196 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00196") != null) { + param = request.getHeader("BenchmarkTest00196"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.execute(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring execute method doesn't return results."); + + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00197.java b/OWASP DATASET/BenchmarkTest00197.java new file mode 100644 index 0000000000000000000000000000000000000000..f4275e752a30f6bb9ac0902a9103cfc3651a9afb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00197.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00197") +public class BenchmarkTest00197 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00197") != null) { + param = request.getHeader("BenchmarkTest00197"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.query( + sql, + new org.springframework.jdbc.core.RowMapper() { + @Override + public String mapRow(java.sql.ResultSet rs, int rowNum) + throws java.sql.SQLException { + try { + return rs.getString("USERNAME"); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper + .hideSQLErrors) { + return "Error processing query."; + } else throw e; + } + } + }); + response.getWriter().println("Your results are: "); + + for (String s : results) { + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(s) + "
"); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00198.java b/OWASP DATASET/BenchmarkTest00198.java new file mode 100644 index 0000000000000000000000000000000000000000..52d3c7cd3679ffbdc8d0bf623d09b688cbbe9d83 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00198.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00198") +public class BenchmarkTest00198 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00198") != null) { + param = request.getHeader("BenchmarkTest00198"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // int results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForInt(sql); + Integer results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Integer.class); + response.getWriter().println("Your results are: " + results); + // System.out.println("Your results are: " + results); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00199.java b/OWASP DATASET/BenchmarkTest00199.java new file mode 100644 index 0000000000000000000000000000000000000000..b0239488b143dab0c883575cf35b19e0c4dd95fa --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00199.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00199") +public class BenchmarkTest00199 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00199") != null) { + param = request.getHeader("BenchmarkTest00199"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // int results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForInt(sql); + Integer results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Integer.class); + response.getWriter().println("Your results are: " + results); + // System.out.println("Your results are: " + results); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00200.java b/OWASP DATASET/BenchmarkTest00200.java new file mode 100644 index 0000000000000000000000000000000000000000..168078f440b6b5b2fa281b5c3b9f61a2b8473c33 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00200.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00200") +public class BenchmarkTest00200 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00200") != null) { + param = request.getHeader("BenchmarkTest00200"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00201.java b/OWASP DATASET/BenchmarkTest00201.java new file mode 100644 index 0000000000000000000000000000000000000000..b07ee826e9389db421c2b09583fd1f76cc663124 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00201.java @@ -0,0 +1,90 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00201") +public class BenchmarkTest00201 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00201") != null) { + param = request.getHeader("BenchmarkTest00201"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + // Chain a bunch of propagators in sequence + String a60073 = param; // assign + StringBuilder b60073 = new StringBuilder(a60073); // stick in stringbuilder + b60073.append(" SafeStuff"); // append some safe content + b60073.replace( + b60073.length() - "Chars".length(), + b60073.length(), + "Chars"); // replace some of the end content + java.util.HashMap map60073 = new java.util.HashMap(); + map60073.put("key60073", b60073.toString()); // put in a collection + String c60073 = (String) map60073.get("key60073"); // get it back out + String d60073 = c60073.substring(0, c60073.length() - 1); // extract most of it + String e60073 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d60073.getBytes()))); // B64 encode and decode it + String f60073 = e60073.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g60073 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g60073); // reflection + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00202.java b/OWASP DATASET/BenchmarkTest00202.java new file mode 100644 index 0000000000000000000000000000000000000000..c0f68de0fe14b64f78441afae676bef2d8698312 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00202.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00202") +public class BenchmarkTest00202 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00202") != null) { + param = request.getHeader("BenchmarkTest00202"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + // Chain a bunch of propagators in sequence + String a15497 = param; // assign + StringBuilder b15497 = new StringBuilder(a15497); // stick in stringbuilder + b15497.append(" SafeStuff"); // append some safe content + b15497.replace( + b15497.length() - "Chars".length(), + b15497.length(), + "Chars"); // replace some of the end content + java.util.HashMap map15497 = new java.util.HashMap(); + map15497.put("key15497", b15497.toString()); // put in a collection + String c15497 = (String) map15497.get("key15497"); // get it back out + String d15497 = c15497.substring(0, c15497.length() - 1); // extract most of it + String e15497 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d15497.getBytes()))); // B64 encode and decode it + String f15497 = e15497.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g15497 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g15497); // reflection + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00203.java b/OWASP DATASET/BenchmarkTest00203.java new file mode 100644 index 0000000000000000000000000000000000000000..2af476ffab90893e0c4bb8937d72bd8fa9fe5344 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00203.java @@ -0,0 +1,72 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00203") +public class BenchmarkTest00203 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00203") != null) { + param = request.getHeader("BenchmarkTest00203"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new String[] {"USERNAME", "PASSWORD"}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00204.java b/OWASP DATASET/BenchmarkTest00204.java new file mode 100644 index 0000000000000000000000000000000000000000..0c57cef4ad0332b5c7e0a1c1510e4e73d6c1b237 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00204.java @@ -0,0 +1,69 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00204") +public class BenchmarkTest00204 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00204") != null) { + param = request.getHeader("BenchmarkTest00204"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new String[] {"USERNAME", "PASSWORD"}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00205.java b/OWASP DATASET/BenchmarkTest00205.java new file mode 100644 index 0000000000000000000000000000000000000000..354f00c30497b2b0df38fd8f7f016e072372e05d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00205.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00205") +public class BenchmarkTest00205 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00205") != null) { + param = request.getHeader("BenchmarkTest00205"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new String[] {"USERNAME", "PASSWORD"}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00206.java b/OWASP DATASET/BenchmarkTest00206.java new file mode 100644 index 0000000000000000000000000000000000000000..95014bc39fa4a6f86d77a216b42dfc85713d8a9c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00206.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00206") +public class BenchmarkTest00206 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00206") != null) { + param = request.getHeader("BenchmarkTest00206"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + // Chain a bunch of propagators in sequence + String a13396 = param; // assign + StringBuilder b13396 = new StringBuilder(a13396); // stick in stringbuilder + b13396.append(" SafeStuff"); // append some safe content + b13396.replace( + b13396.length() - "Chars".length(), + b13396.length(), + "Chars"); // replace some of the end content + java.util.HashMap map13396 = new java.util.HashMap(); + map13396.put("key13396", b13396.toString()); // put in a collection + String c13396 = (String) map13396.get("key13396"); // get it back out + String d13396 = c13396.substring(0, c13396.length() - 1); // extract most of it + String e13396 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d13396.getBytes()))); // B64 encode and decode it + String f13396 = e13396.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g13396 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g13396); // reflection + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new String[] {"USERNAME", "PASSWORD"}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00207.java b/OWASP DATASET/BenchmarkTest00207.java new file mode 100644 index 0000000000000000000000000000000000000000..70ff7a52adfa2bc4bfebc9b4b503a0bcdf45ba14 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00207.java @@ -0,0 +1,90 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest00207") +public class BenchmarkTest00207 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest00207") != null) { + param = request.getHeader("BenchmarkTest00207"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + String result = xp.evaluate(expression, xmlDocument); + + response.getWriter().println("Your query results are: " + result + "
"); + + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00208.java b/OWASP DATASET/BenchmarkTest00208.java new file mode 100644 index 0000000000000000000000000000000000000000..e2a7460927aabe0c3d01736777a74f0d0bce9f73 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00208.java @@ -0,0 +1,172 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00208") +public class BenchmarkTest00208 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00209.java b/OWASP DATASET/BenchmarkTest00209.java new file mode 100644 index 0000000000000000000000000000000000000000..f0f5508c7f4a7fac99e8e2eb7dd94c31eab4cd91 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00209.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00209") +public class BenchmarkTest00209 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + StringBuilder sbxyz43235 = new StringBuilder(param); + String bar = sbxyz43235.append("_SafeStuff").toString(); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = org.owasp.benchmark.helpers.Utils.getCipher(); + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00210.java b/OWASP DATASET/BenchmarkTest00210.java new file mode 100644 index 0000000000000000000000000000000000000000..27939e7269f1683ee9e474802c426cea6a189234 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00210.java @@ -0,0 +1,136 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00210") +public class BenchmarkTest00210 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00211.java b/OWASP DATASET/BenchmarkTest00211.java new file mode 100644 index 0000000000000000000000000000000000000000..054a9c07ef26bdf23e51e528d09fbd2b2143738f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00211.java @@ -0,0 +1,135 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00211") +public class BenchmarkTest00211 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "AES/CCM/NoPadding", java.security.Security.getProvider("BC")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00212.java b/OWASP DATASET/BenchmarkTest00212.java new file mode 100644 index 0000000000000000000000000000000000000000..2a84fac295517f5e5e83f38b6e6c2fdb0a673523 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00212.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00212") +public class BenchmarkTest00212 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "AES/CCM/NoPadding", java.security.Security.getProvider("BC")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00213.java b/OWASP DATASET/BenchmarkTest00213.java new file mode 100644 index 0000000000000000000000000000000000000000..ffe3c9f91cdb9a29b5aea1b92a2f5e8f25bf8dab --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00213.java @@ -0,0 +1,144 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00213") +public class BenchmarkTest00213 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + // java.security.SecureRandom random = new java.security.SecureRandom(); + // byte[] iv = random.generateSeed(16); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg2", "AES/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00214.java b/OWASP DATASET/BenchmarkTest00214.java new file mode 100644 index 0000000000000000000000000000000000000000..9cd8e1aeef25d6b9d3a55665f0f72fa4bc8c94b4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00214.java @@ -0,0 +1,134 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00214") +public class BenchmarkTest00214 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = param; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + // java.security.SecureRandom random = new java.security.SecureRandom(); + // byte[] iv = random.generateSeed(16); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg2", "AES/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00215.java b/OWASP DATASET/BenchmarkTest00215.java new file mode 100644 index 0000000000000000000000000000000000000000..2acfcd4ddaa75f2b6b51714037821e95ad85b358 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00215.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00215") +public class BenchmarkTest00215 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = param; + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00216.java b/OWASP DATASET/BenchmarkTest00216.java new file mode 100644 index 0000000000000000000000000000000000000000..a0376bad2dacbb0ff66f78593472f47941270a74 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00216.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00216") +public class BenchmarkTest00216 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + java.io.File fileTarget = + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR, bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00217.java b/OWASP DATASET/BenchmarkTest00217.java new file mode 100644 index 0000000000000000000000000000000000000000..0fff87e0ab90febe234a67e0ae09a064a44139be --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00217.java @@ -0,0 +1,100 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00217") +public class BenchmarkTest00217 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + // Chain a bunch of propagators in sequence + String a26348 = param; // assign + StringBuilder b26348 = new StringBuilder(a26348); // stick in stringbuilder + b26348.append(" SafeStuff"); // append some safe content + b26348.replace( + b26348.length() - "Chars".length(), + b26348.length(), + "Chars"); // replace some of the end content + java.util.HashMap map26348 = new java.util.HashMap(); + map26348.put("key26348", b26348.toString()); // put in a collection + String c26348 = (String) map26348.get("key26348"); // get it back out + String d26348 = c26348.substring(0, c26348.length() - 1); // extract most of it + String e26348 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d26348.getBytes()))); // B64 encode and decode it + String f26348 = e26348.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g26348 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g26348); // reflection + + java.io.File fileTarget = new java.io.File(bar, "/Test.txt"); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00218.java b/OWASP DATASET/BenchmarkTest00218.java new file mode 100644 index 0000000000000000000000000000000000000000..690cb4259ecdc65e0ee8d28e5a139a515abfae2f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00218.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00218") +public class BenchmarkTest00218 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + // FILE URIs are tricky because they are different between Mac and Windows because of lack + // of standardization. + // Mac requires an extra slash for some reason. + String startURIslashes = ""; + if (System.getProperty("os.name").indexOf("Windows") != -1) + if (System.getProperty("os.name").indexOf("Windows") != -1) startURIslashes = "/"; + else startURIslashes = "//"; + + try { + java.net.URI fileURI = + new java.net.URI( + "file", + null, + startURIslashes + + org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + .replace('\\', java.io.File.separatorChar) + .replace(' ', '_') + + bar, + null, + null); + java.io.File fileTarget = new java.io.File(fileURI); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } catch (java.net.URISyntaxException e) { + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00219.java b/OWASP DATASET/BenchmarkTest00219.java new file mode 100644 index 0000000000000000000000000000000000000000..2500cdb960c9e058519442fefcbfbef2dff649e4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00219.java @@ -0,0 +1,107 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00219") +public class BenchmarkTest00219 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(new java.io.File(fileName)); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting FileInputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00220.java b/OWASP DATASET/BenchmarkTest00220.java new file mode 100644 index 0000000000000000000000000000000000000000..b1911535a76f6a6d8bfdeff1a55148dab75de116 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00220.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00220") +public class BenchmarkTest00220 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + // Chain a bunch of propagators in sequence + String a25969 = param; // assign + StringBuilder b25969 = new StringBuilder(a25969); // stick in stringbuilder + b25969.append(" SafeStuff"); // append some safe content + b25969.replace( + b25969.length() - "Chars".length(), + b25969.length(), + "Chars"); // replace some of the end content + java.util.HashMap map25969 = new java.util.HashMap(); + map25969.put("key25969", b25969.toString()); // put in a collection + String c25969 = (String) map25969.get("key25969"); // get it back out + String d25969 = c25969.substring(0, c25969.length() - 1); // extract most of it + String e25969 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d25969.getBytes()))); // B64 encode and decode it + String f25969 = e25969.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g25969 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g25969); // reflection + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName, false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00221.java b/OWASP DATASET/BenchmarkTest00221.java new file mode 100644 index 0000000000000000000000000000000000000000..566323eec31f0f022039c9de4c41577ed9d2ef68 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00221.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00221") +public class BenchmarkTest00221 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName, false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00222.java b/OWASP DATASET/BenchmarkTest00222.java new file mode 100644 index 0000000000000000000000000000000000000000..2347f3c1b982f63afa4745f55fa765e1fc8d91db --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00222.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00222") +public class BenchmarkTest00222 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00223.java b/OWASP DATASET/BenchmarkTest00223.java new file mode 100644 index 0000000000000000000000000000000000000000..199272a2b3cbc46dccc85a8f6f7715c4ef770e73 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00223.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00223") +public class BenchmarkTest00223 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = "safe!"; + java.util.HashMap map13848 = new java.util.HashMap(); + map13848.put("keyA-13848", "a-Value"); // put some stuff in the collection + map13848.put("keyB-13848", param); // put it in a collection + map13848.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map13848.get("keyB-13848"); // get it back out + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("SHA1", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00224.java b/OWASP DATASET/BenchmarkTest00224.java new file mode 100644 index 0000000000000000000000000000000000000000..aeccf9d685e34136c90d96d3803c23f77a3d0da3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00224.java @@ -0,0 +1,125 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00224") +public class BenchmarkTest00224 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = param; + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("sha-384", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("sha-384", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00225.java b/OWASP DATASET/BenchmarkTest00225.java new file mode 100644 index 0000000000000000000000000000000000000000..4eed2bdab279d1bc322329b8af791eff128c9300 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00225.java @@ -0,0 +1,123 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00225") +public class BenchmarkTest00225 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + try { + java.security.MessageDigest md = + java.security.MessageDigest.getInstance("SHA-512", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00226.java b/OWASP DATASET/BenchmarkTest00226.java new file mode 100644 index 0000000000000000000000000000000000000000..ba20ee9375bca9accdcff18d47ce0a424606146b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00226.java @@ -0,0 +1,122 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00226") +public class BenchmarkTest00226 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = "safe!"; + java.util.HashMap map56895 = new java.util.HashMap(); + map56895.put("keyA-56895", "a_Value"); // put some stuff in the collection + map56895.put("keyB-56895", param); // put it in a collection + map56895.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map56895.get("keyB-56895"); // get it back out + bar = (String) map56895.get("keyA-56895"); // get safe value back out + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00227.java b/OWASP DATASET/BenchmarkTest00227.java new file mode 100644 index 0000000000000000000000000000000000000000..97c1e4bab59c81862e261f5f81f1c5d0293cf8e9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00227.java @@ -0,0 +1,137 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00227") +public class BenchmarkTest00227 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + // Chain a bunch of propagators in sequence + String a15913 = param; // assign + StringBuilder b15913 = new StringBuilder(a15913); // stick in stringbuilder + b15913.append(" SafeStuff"); // append some safe content + b15913.replace( + b15913.length() - "Chars".length(), + b15913.length(), + "Chars"); // replace some of the end content + java.util.HashMap map15913 = new java.util.HashMap(); + map15913.put("key15913", b15913.toString()); // put in a collection + String c15913 = (String) map15913.get("key15913"); // get it back out + String d15913 = c15913.substring(0, c15913.length() - 1); // extract most of it + String e15913 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d15913.getBytes()))); // B64 encode and decode it + String f15913 = e15913.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g15913 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g15913); // reflection + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00228.java b/OWASP DATASET/BenchmarkTest00228.java new file mode 100644 index 0000000000000000000000000000000000000000..17dfc2b658d26a6c9d85d4fdb664c79d24e2aa73 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00228.java @@ -0,0 +1,126 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00228") +public class BenchmarkTest00228 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00229.java b/OWASP DATASET/BenchmarkTest00229.java new file mode 100644 index 0000000000000000000000000000000000000000..0912a4a94f846d5e191ce5b18fb80e599bbbbe74 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00229.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00229") +public class BenchmarkTest00229 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00230.java b/OWASP DATASET/BenchmarkTest00230.java new file mode 100644 index 0000000000000000000000000000000000000000..9d1358ff4851e6ad0b4fe54b16b4f09efbeb52af --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00230.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00230") +public class BenchmarkTest00230 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + byte[] bytes = new byte[10]; + new java.util.Random().nextBytes(bytes); + String rememberMeKey = org.owasp.esapi.ESAPI.encoder().encodeForBase64(bytes, true); + + String user = "Byron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextBytes() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00231.java b/OWASP DATASET/BenchmarkTest00231.java new file mode 100644 index 0000000000000000000000000000000000000000..28fdfa5db7b42a4943de7245c9710c3f87120c40 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00231.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00231") +public class BenchmarkTest00231 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = "safe!"; + java.util.HashMap map59585 = new java.util.HashMap(); + map59585.put("keyA-59585", "a-Value"); // put some stuff in the collection + map59585.put("keyB-59585", param); // put it in a collection + map59585.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map59585.get("keyB-59585"); // get it back out + + double stuff = new java.util.Random().nextGaussian(); + String rememberMeKey = Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "Gayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter() + .println("Weak Randomness Test java.util.Random.nextGaussian() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00232.java b/OWASP DATASET/BenchmarkTest00232.java new file mode 100644 index 0000000000000000000000000000000000000000..440a79529ffccf9d9ada0a0f36a2cae9ea9e2ff0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00232.java @@ -0,0 +1,118 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00232") +public class BenchmarkTest00232 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = "safe!"; + java.util.HashMap map84140 = new java.util.HashMap(); + map84140.put("keyA-84140", "a_Value"); // put some stuff in the collection + map84140.put("keyB-84140", param); // put it in a collection + map84140.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map84140.get("keyB-84140"); // get it back out + bar = (String) map84140.get("keyA-84140"); // get safe value back out + + double stuff = new java.util.Random().nextGaussian(); + String rememberMeKey = Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "Gayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter() + .println("Weak Randomness Test java.util.Random.nextGaussian() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00233.java b/OWASP DATASET/BenchmarkTest00233.java new file mode 100644 index 0000000000000000000000000000000000000000..503504217503dc9e72bdf5b2ff24034b48ce49ae --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00233.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00233") +public class BenchmarkTest00233 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + int randNumber = new java.util.Random().nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "Inga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt(int) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00234.java b/OWASP DATASET/BenchmarkTest00234.java new file mode 100644 index 0000000000000000000000000000000000000000..95adcf40d9cbd306d71838cf8d118e20a956e595 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00234.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00234") +public class BenchmarkTest00234 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = "safe!"; + java.util.HashMap map35995 = new java.util.HashMap(); + map35995.put("keyA-35995", "a_Value"); // put some stuff in the collection + map35995.put("keyB-35995", param); // put it in a collection + map35995.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map35995.get("keyB-35995"); // get it back out + bar = (String) map35995.get("keyA-35995"); // get safe value back out + + int randNumber = new java.util.Random().nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "Inga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt(int) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00235.java b/OWASP DATASET/BenchmarkTest00235.java new file mode 100644 index 0000000000000000000000000000000000000000..d5783a7b4ab1a79fb9a7c5faa368db4c8b02362a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00235.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00235") +public class BenchmarkTest00235 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00236.java b/OWASP DATASET/BenchmarkTest00236.java new file mode 100644 index 0000000000000000000000000000000000000000..fe9c20ea47b1fe307287fb25f02d40135b631d2f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00236.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00236") +public class BenchmarkTest00236 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00237.java b/OWASP DATASET/BenchmarkTest00237.java new file mode 100644 index 0000000000000000000000000000000000000000..82a63a50a7caf3657356d1bbafcde9b3ca1d168c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00237.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00237") +public class BenchmarkTest00237 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00238.java b/OWASP DATASET/BenchmarkTest00238.java new file mode 100644 index 0000000000000000000000000000000000000000..f37c526e4046d02b3e8947131aef775156a2c9ce --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00238.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00238") +public class BenchmarkTest00238 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00239.java b/OWASP DATASET/BenchmarkTest00239.java new file mode 100644 index 0000000000000000000000000000000000000000..6be15dd7243b27cd8912abaa82b9d101dfa8d615 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00239.java @@ -0,0 +1,132 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00239") +public class BenchmarkTest00239 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + // Chain a bunch of propagators in sequence + String a22450 = param; // assign + StringBuilder b22450 = new StringBuilder(a22450); // stick in stringbuilder + b22450.append(" SafeStuff"); // append some safe content + b22450.replace( + b22450.length() - "Chars".length(), + b22450.length(), + "Chars"); // replace some of the end content + java.util.HashMap map22450 = new java.util.HashMap(); + map22450.put("key22450", b22450.toString()); // put in a collection + String c22450 = (String) map22450.get("key22450"); // get it back out + String d22450 = c22450.substring(0, c22450.length() - 1); // extract most of it + String e22450 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d22450.getBytes()))); // B64 encode and decode it + String f22450 = e22450.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f22450); // reflection + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00240.java b/OWASP DATASET/BenchmarkTest00240.java new file mode 100644 index 0000000000000000000000000000000000000000..9ab4de1531260b8eee8914ea5ca92a4b67d088fa --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00240.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00240") +public class BenchmarkTest00240 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00241.java b/OWASP DATASET/BenchmarkTest00241.java new file mode 100644 index 0000000000000000000000000000000000000000..65620d4ce1a09b01e151f4517d61d0a0bf23afab --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00241.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest00241") +public class BenchmarkTest00241 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00242.java b/OWASP DATASET/BenchmarkTest00242.java new file mode 100644 index 0000000000000000000000000000000000000000..83729931e47d4f488eb6f5c2ecbfd80452214c90 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00242.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest00242") +public class BenchmarkTest00242 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00243.java b/OWASP DATASET/BenchmarkTest00243.java new file mode 100644 index 0000000000000000000000000000000000000000..4f7c79e357edef2c38e3389c216d612c72a81e6a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00243.java @@ -0,0 +1,134 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00243") +public class BenchmarkTest00243 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = "safe!"; + java.util.HashMap map86025 = new java.util.HashMap(); + map86025.put("keyA-86025", "a-Value"); // put some stuff in the collection + map86025.put("keyB-86025", param); // put it in a collection + map86025.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map86025.get("keyB-86025"); // get it back out + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + getNextNumber(numGen, randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeBystander"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } + + void getNextNumber(java.util.Random generator, byte[] barray) { + generator.nextBytes(barray); + } +} diff --git a/OWASP DATASET/BenchmarkTest00244.java b/OWASP DATASET/BenchmarkTest00244.java new file mode 100644 index 0000000000000000000000000000000000000000..f758f33b90033e0ba707f0bd56d6094a1005100f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00244.java @@ -0,0 +1,134 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00244") +public class BenchmarkTest00244 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + getNextNumber(numGen, randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeBystander"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } + + void getNextNumber(java.util.Random generator, byte[] barray) { + generator.nextBytes(barray); + } +} diff --git a/OWASP DATASET/BenchmarkTest00245.java b/OWASP DATASET/BenchmarkTest00245.java new file mode 100644 index 0000000000000000000000000000000000000000..42f7494f13be08e8436d81a855126785a8edb637 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00245.java @@ -0,0 +1,146 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00245") +public class BenchmarkTest00245 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + // Chain a bunch of propagators in sequence + String a73565 = param; // assign + StringBuilder b73565 = new StringBuilder(a73565); // stick in stringbuilder + b73565.append(" SafeStuff"); // append some safe content + b73565.replace( + b73565.length() - "Chars".length(), + b73565.length(), + "Chars"); // replace some of the end content + java.util.HashMap map73565 = new java.util.HashMap(); + map73565.put("key73565", b73565.toString()); // put in a collection + String c73565 = (String) map73565.get("key73565"); // get it back out + String d73565 = c73565.substring(0, c73565.length() - 1); // extract most of it + String e73565 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d73565.getBytes()))); // B64 encode and decode it + String f73565 = e73565.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g73565 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g73565); // reflection + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + double rand = getNextNumber(numGen); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonatella"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } + + double getNextNumber(java.util.Random generator) { + return generator.nextDouble(); + } +} diff --git a/OWASP DATASET/BenchmarkTest00246.java b/OWASP DATASET/BenchmarkTest00246.java new file mode 100644 index 0000000000000000000000000000000000000000..ddc6c3623aad70b65dc42b033d45833f3f85e3fc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00246.java @@ -0,0 +1,131 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00246") +public class BenchmarkTest00246 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00247.java b/OWASP DATASET/BenchmarkTest00247.java new file mode 100644 index 0000000000000000000000000000000000000000..bc51413c36f070a0eb91b20b58bbac4271940d54 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00247.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00247") +public class BenchmarkTest00247 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz47256 = new StringBuilder(param); + bar = sbxyz47256.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00248.java b/OWASP DATASET/BenchmarkTest00248.java new file mode 100644 index 0000000000000000000000000000000000000000..17091c128b3c9ed335010fd4c90a857828535697 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00248.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00248") +public class BenchmarkTest00248 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + try { + long l = java.security.SecureRandom.getInstance("SHA1PRNG").nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "SafeLogan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextLong() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextLong() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00249.java b/OWASP DATASET/BenchmarkTest00249.java new file mode 100644 index 0000000000000000000000000000000000000000..86b2eb81a87f73ca5e8d8561f81aa0c8694b718a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00249.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00249") +public class BenchmarkTest00249 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + try { + long l = java.security.SecureRandom.getInstance("SHA1PRNG").nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "SafeLogan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextLong() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextLong() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00250.java b/OWASP DATASET/BenchmarkTest00250.java new file mode 100644 index 0000000000000000000000000000000000000000..e31aba4449ca8265e5fbd799902df72abef23ee2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00250.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00250") +public class BenchmarkTest00250 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + // javax.servlet.http.HttpSession.putValue(java.lang.String^,java.lang.Object) + request.getSession().putValue(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: 10340 saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00251.java b/OWASP DATASET/BenchmarkTest00251.java new file mode 100644 index 0000000000000000000000000000000000000000..d5146ddbf6626a6e97e323e08e2d2ac6595684ac --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00251.java @@ -0,0 +1,73 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00251") +public class BenchmarkTest00251 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00252.java b/OWASP DATASET/BenchmarkTest00252.java new file mode 100644 index 0000000000000000000000000000000000000000..5ba961de52322466df5fed86b7d7dabbb4ce3f1d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00252.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00252") +public class BenchmarkTest00252 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String^,java.lang.Object) + request.getSession().setAttribute(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: '10340' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00253.java b/OWASP DATASET/BenchmarkTest00253.java new file mode 100644 index 0000000000000000000000000000000000000000..216239210cc68f245a77850a205ec9dfc27bbb4c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00253.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00253") +public class BenchmarkTest00253 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00254.java b/OWASP DATASET/BenchmarkTest00254.java new file mode 100644 index 0000000000000000000000000000000000000000..21bcd5b09895b8b2baff62484ca2b49185627e10 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00254.java @@ -0,0 +1,162 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00254") +public class BenchmarkTest00254 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00254"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "DES/CBC/PKCS5PADDING", java.security.Security.getProvider("SunJCE")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00255.java b/OWASP DATASET/BenchmarkTest00255.java new file mode 100644 index 0000000000000000000000000000000000000000..bb81e8379357428d3feae529b99a3eaf30d668c0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00255.java @@ -0,0 +1,159 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00255") +public class BenchmarkTest00255 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00255"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00256.java b/OWASP DATASET/BenchmarkTest00256.java new file mode 100644 index 0000000000000000000000000000000000000000..7a52b921b1a7cec7f027d40839bd81811823a053 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00256.java @@ -0,0 +1,169 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00256") +public class BenchmarkTest00256 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00256"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00257.java b/OWASP DATASET/BenchmarkTest00257.java new file mode 100644 index 0000000000000000000000000000000000000000..c4969bb69ef490d99020fa65c772ff439d9743cf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00257.java @@ -0,0 +1,160 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00257") +public class BenchmarkTest00257 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00257"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + StringBuilder sbxyz60568 = new StringBuilder(param); + String bar = sbxyz60568.append("_SafeStuff").toString(); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00258.java b/OWASP DATASET/BenchmarkTest00258.java new file mode 100644 index 0000000000000000000000000000000000000000..916d4c76c73db9fe7bc9ab9736596d2e81734e1a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00258.java @@ -0,0 +1,159 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00258") +public class BenchmarkTest00258 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00258"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00259.java b/OWASP DATASET/BenchmarkTest00259.java new file mode 100644 index 0000000000000000000000000000000000000000..3ca458a19a8eb2a99090918dcf34f9d393e12556 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00259.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00259") +public class BenchmarkTest00259 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00259"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = param; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = org.owasp.benchmark.helpers.Utils.getCipher(); + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00260.java b/OWASP DATASET/BenchmarkTest00260.java new file mode 100644 index 0000000000000000000000000000000000000000..35b23c55b25cd4f5e608326a3455f26f94f9c808 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00260.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00260") +public class BenchmarkTest00260 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00260"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = org.owasp.benchmark.helpers.Utils.getCipher(); + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00261.java b/OWASP DATASET/BenchmarkTest00261.java new file mode 100644 index 0000000000000000000000000000000000000000..f9da71b74d5bec7e4b371fa245038880757a3cbd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00261.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00261") +public class BenchmarkTest00261 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00261"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + // Chain a bunch of propagators in sequence + String a3000 = param; // assign + StringBuilder b3000 = new StringBuilder(a3000); // stick in stringbuilder + b3000.append(" SafeStuff"); // append some safe content + b3000.replace( + b3000.length() - "Chars".length(), + b3000.length(), + "Chars"); // replace some of the end content + java.util.HashMap map3000 = new java.util.HashMap(); + map3000.put("key3000", b3000.toString()); // put in a collection + String c3000 = (String) map3000.get("key3000"); // get it back out + String d3000 = c3000.substring(0, c3000.length() - 1); // extract most of it + String e3000 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d3000.getBytes()))); // B64 encode and decode it + String f3000 = e3000.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g3000 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g3000); // reflection + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00262.java b/OWASP DATASET/BenchmarkTest00262.java new file mode 100644 index 0000000000000000000000000000000000000000..d896ae41f2fa87d79b63f9e47d37ad72ab4a519d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00262.java @@ -0,0 +1,90 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00262") +public class BenchmarkTest00262 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00262"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + java.io.File fileTarget = new java.io.File(bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00263.java b/OWASP DATASET/BenchmarkTest00263.java new file mode 100644 index 0000000000000000000000000000000000000000..373607bd328ccf9c7febf542bb7ad4f6a6c07492 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00263.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00263") +public class BenchmarkTest00263 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00263"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(new java.io.File(fileName)); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting FileInputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00264.java b/OWASP DATASET/BenchmarkTest00264.java new file mode 100644 index 0000000000000000000000000000000000000000..bd031aeaaa579654a4c1c1f94f3e3823531ac3b3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00264.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00264") +public class BenchmarkTest00264 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00264"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(new java.io.File(fileName)); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting FileInputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00265.java b/OWASP DATASET/BenchmarkTest00265.java new file mode 100644 index 0000000000000000000000000000000000000000..7ed741bc2797825ea3ec33b8239e8502907b1923 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00265.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00265") +public class BenchmarkTest00265 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00265"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00266.java b/OWASP DATASET/BenchmarkTest00266.java new file mode 100644 index 0000000000000000000000000000000000000000..4adee10a2e7e9d61d31db2c004a713607e6d130b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00266.java @@ -0,0 +1,122 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00266") +public class BenchmarkTest00266 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00266"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "safe!"; + java.util.HashMap map42712 = new java.util.HashMap(); + map42712.put("keyA-42712", "a-Value"); // put some stuff in the collection + map42712.put("keyB-42712", param); // put it in a collection + map42712.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map42712.get("keyB-42712"); // get it back out + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("SHA1", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00267.java b/OWASP DATASET/BenchmarkTest00267.java new file mode 100644 index 0000000000000000000000000000000000000000..3f714658f98cf4e39045b5a540b4babedc750f76 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00267.java @@ -0,0 +1,118 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00267") +public class BenchmarkTest00267 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00267"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + StringBuilder sbxyz11795 = new StringBuilder(param); + String bar = sbxyz11795.append("_SafeStuff").toString(); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("SHA1", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00268.java b/OWASP DATASET/BenchmarkTest00268.java new file mode 100644 index 0000000000000000000000000000000000000000..30df332c720a4667932e6afdbc6a00e3f7d987dd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00268.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00268") +public class BenchmarkTest00268 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00268"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00269.java b/OWASP DATASET/BenchmarkTest00269.java new file mode 100644 index 0000000000000000000000000000000000000000..1021456d949a5155ed6432136a10711a79eef604 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00269.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00269") +public class BenchmarkTest00269 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00269"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00270.java b/OWASP DATASET/BenchmarkTest00270.java new file mode 100644 index 0000000000000000000000000000000000000000..d9126b889d442510b37075e97680332a67fd99c5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00270.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00270") +public class BenchmarkTest00270 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00270"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + try { + java.security.MessageDigest md = + java.security.MessageDigest.getInstance("SHA-512", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00271.java b/OWASP DATASET/BenchmarkTest00271.java new file mode 100644 index 0000000000000000000000000000000000000000..e73ba4512cbe86868a4b8259329a0fa28c5c3704 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00271.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00271") +public class BenchmarkTest00271 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00271"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + // Chain a bunch of propagators in sequence + String a75009 = param; // assign + StringBuilder b75009 = new StringBuilder(a75009); // stick in stringbuilder + b75009.append(" SafeStuff"); // append some safe content + b75009.replace( + b75009.length() - "Chars".length(), + b75009.length(), + "Chars"); // replace some of the end content + java.util.HashMap map75009 = new java.util.HashMap(); + map75009.put("key75009", b75009.toString()); // put in a collection + String c75009 = (String) map75009.get("key75009"); // get it back out + String d75009 = c75009.substring(0, c75009.length() - 1); // extract most of it + String e75009 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d75009.getBytes()))); // B64 encode and decode it + String f75009 = e75009.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f75009); // reflection + + try { + java.security.MessageDigest md = + java.security.MessageDigest.getInstance("SHA-512", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00272.java b/OWASP DATASET/BenchmarkTest00272.java new file mode 100644 index 0000000000000000000000000000000000000000..cb8b9edae2321e183e04b7a230853570b6c5b2a6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00272.java @@ -0,0 +1,123 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00272") +public class BenchmarkTest00272 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00272"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00273.java b/OWASP DATASET/BenchmarkTest00273.java new file mode 100644 index 0000000000000000000000000000000000000000..4af7de2fa62325285a6fe02aa1fc512c0145b19c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00273.java @@ -0,0 +1,118 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00273") +public class BenchmarkTest00273 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00273"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00274.java b/OWASP DATASET/BenchmarkTest00274.java new file mode 100644 index 0000000000000000000000000000000000000000..f7a89044371a7bef6403d462243820af5209db6c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00274.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00274") +public class BenchmarkTest00274 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00274"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00275.java b/OWASP DATASET/BenchmarkTest00275.java new file mode 100644 index 0000000000000000000000000000000000000000..a97e29fc74166329b1c394ccbef15a10886be38e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00275.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00275") +public class BenchmarkTest00275 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + // Chain a bunch of propagators in sequence + String a28150 = param; // assign + StringBuilder b28150 = new StringBuilder(a28150); // stick in stringbuilder + b28150.append(" SafeStuff"); // append some safe content + b28150.replace( + b28150.length() - "Chars".length(), + b28150.length(), + "Chars"); // replace some of the end content + java.util.HashMap map28150 = new java.util.HashMap(); + map28150.put("key28150", b28150.toString()); // put in a collection + String c28150 = (String) map28150.get("key28150"); // get it back out + String d28150 = c28150.substring(0, c28150.length() - 1); // extract most of it + String e28150 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d28150.getBytes()))); // B64 encode and decode it + String f28150 = e28150.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g28150 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g28150); // reflection + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar.toCharArray()); + } +} diff --git a/OWASP DATASET/BenchmarkTest00276.java b/OWASP DATASET/BenchmarkTest00276.java new file mode 100644 index 0000000000000000000000000000000000000000..b889dc4ecb2bb324048dfb9f69c9d5f252033c6e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00276.java @@ -0,0 +1,63 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00276") +public class BenchmarkTest00276 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00277.java b/OWASP DATASET/BenchmarkTest00277.java new file mode 100644 index 0000000000000000000000000000000000000000..78130e9157055604e953628d05c007f7d5073d12 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00277.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00277") +public class BenchmarkTest00277 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + // Chain a bunch of propagators in sequence + String a54571 = param; // assign + StringBuilder b54571 = new StringBuilder(a54571); // stick in stringbuilder + b54571.append(" SafeStuff"); // append some safe content + b54571.replace( + b54571.length() - "Chars".length(), + b54571.length(), + "Chars"); // replace some of the end content + java.util.HashMap map54571 = new java.util.HashMap(); + map54571.put("key54571", b54571.toString()); // put in a collection + String c54571 = (String) map54571.get("key54571"); // get it back out + String d54571 = c54571.substring(0, c54571.length() - 1); // extract most of it + String e54571 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d54571.getBytes()))); // B64 encode and decode it + String f54571 = e54571.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g54571 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g54571); // reflection + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00278.java b/OWASP DATASET/BenchmarkTest00278.java new file mode 100644 index 0000000000000000000000000000000000000000..1322fb1be8ac262904d849d16fd240f1d556ab76 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00278.java @@ -0,0 +1,58 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00278") +public class BenchmarkTest00278 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00279.java b/OWASP DATASET/BenchmarkTest00279.java new file mode 100644 index 0000000000000000000000000000000000000000..4ebe2d25b974a2f88bd99c713e2c2eefea7ae3ec --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00279.java @@ -0,0 +1,68 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00279") +public class BenchmarkTest00279 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00280.java b/OWASP DATASET/BenchmarkTest00280.java new file mode 100644 index 0000000000000000000000000000000000000000..b8d9cc3ec646dfbf8843079794f02edc68b54620 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00280.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00280") +public class BenchmarkTest00280 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00281.java b/OWASP DATASET/BenchmarkTest00281.java new file mode 100644 index 0000000000000000000000000000000000000000..8e76827cb633b7676f2d86563225cc9c1c22dc54 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00281.java @@ -0,0 +1,64 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00281") +public class BenchmarkTest00281 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(java.util.Locale.US, bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00282.java b/OWASP DATASET/BenchmarkTest00282.java new file mode 100644 index 0000000000000000000000000000000000000000..f2eb0a6410f6370d0e15250ebce547dfb715a806 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00282.java @@ -0,0 +1,59 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00282") +public class BenchmarkTest00282 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {bar, "b"}; + response.getWriter().printf("Formatted like: %1$s and %2$s.", obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00283.java b/OWASP DATASET/BenchmarkTest00283.java new file mode 100644 index 0000000000000000000000000000000000000000..4dc280288f3c28117ad80dd193523e013f0b71a9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00283.java @@ -0,0 +1,58 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00283") +public class BenchmarkTest00283 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar.toCharArray()); + } +} diff --git a/OWASP DATASET/BenchmarkTest00284.java b/OWASP DATASET/BenchmarkTest00284.java new file mode 100644 index 0000000000000000000000000000000000000000..e747254ae9bb171bab59cd81d0774598e8f02c4d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00284.java @@ -0,0 +1,58 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00284") +public class BenchmarkTest00284 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = param; + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00285.java b/OWASP DATASET/BenchmarkTest00285.java new file mode 100644 index 0000000000000000000000000000000000000000..cf1b75cd4fa9ff56961a7ce0c541c74c1316adc2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00285.java @@ -0,0 +1,58 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00285") +public class BenchmarkTest00285 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00286.java b/OWASP DATASET/BenchmarkTest00286.java new file mode 100644 index 0000000000000000000000000000000000000000..5931242784e2a788c5d999b59b30ef1b78e6edc9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00286.java @@ -0,0 +1,58 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00286") +public class BenchmarkTest00286 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar.toCharArray()); + } +} diff --git a/OWASP DATASET/BenchmarkTest00287.java b/OWASP DATASET/BenchmarkTest00287.java new file mode 100644 index 0000000000000000000000000000000000000000..75efb8da52f87af06324e80301b14f2d6ec6dc3b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00287.java @@ -0,0 +1,62 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00287") +public class BenchmarkTest00287 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = param; + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar.toCharArray(), 0, length); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00288.java b/OWASP DATASET/BenchmarkTest00288.java new file mode 100644 index 0000000000000000000000000000000000000000..25d314d1628601c29b1ed3eecc2ef9426742ff77 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00288.java @@ -0,0 +1,68 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00288") +public class BenchmarkTest00288 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "safe!"; + java.util.HashMap map34285 = new java.util.HashMap(); + map34285.put("keyA-34285", "a_Value"); // put some stuff in the collection + map34285.put("keyB-34285", param); // put it in a collection + map34285.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map34285.get("keyB-34285"); // get it back out + bar = (String) map34285.get("keyA-34285"); // get safe value back out + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar.toCharArray(), 0, length); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00289.java b/OWASP DATASET/BenchmarkTest00289.java new file mode 100644 index 0000000000000000000000000000000000000000..01ca02d0f87238add08980f410a880f56a08f7f2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00289.java @@ -0,0 +1,58 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00289") +public class BenchmarkTest00289 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00290.java b/OWASP DATASET/BenchmarkTest00290.java new file mode 100644 index 0000000000000000000000000000000000000000..be683649787807d6f8bde7f3bbaa4f52b83c2e63 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00290.java @@ -0,0 +1,59 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00290") +public class BenchmarkTest00290 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + StringBuilder sbxyz73567 = new StringBuilder(param); + String bar = sbxyz73567.append("_SafeStuff").toString(); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00291.java b/OWASP DATASET/BenchmarkTest00291.java new file mode 100644 index 0000000000000000000000000000000000000000..8ed353c07a9f7ad96bfd433f36dbb01024111aad --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00291.java @@ -0,0 +1,61 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00291") +public class BenchmarkTest00291 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00292.java b/OWASP DATASET/BenchmarkTest00292.java new file mode 100644 index 0000000000000000000000000000000000000000..cb23fe762a1894af0732af3eba880adf96902fe5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00292.java @@ -0,0 +1,65 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00292") +public class BenchmarkTest00292 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar, 0, length); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00293.java b/OWASP DATASET/BenchmarkTest00293.java new file mode 100644 index 0000000000000000000000000000000000000000..73a616ec51053ab643b08c19c42b644daeaaf6c9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00293.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00293") +public class BenchmarkTest00293 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00293"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(); + + pb.command(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00294.java b/OWASP DATASET/BenchmarkTest00294.java new file mode 100644 index 0000000000000000000000000000000000000000..6326a6e9afe3b075e634593926b1be849292ab5e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00294.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00294") +public class BenchmarkTest00294 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00294"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00295.java b/OWASP DATASET/BenchmarkTest00295.java new file mode 100644 index 0000000000000000000000000000000000000000..61b5910b1f688b0d3f59047bfcf11400169fcfd4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00295.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00295") +public class BenchmarkTest00295 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00295"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + String a1 = ""; + String a2 = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + } else { + a1 = "sh"; + a2 = "-c"; + } + String[] args = {a1, a2, "echo " + bar}; + + ProcessBuilder pb = new ProcessBuilder(args); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.lang.String[]) Test Case"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00296.java b/OWASP DATASET/BenchmarkTest00296.java new file mode 100644 index 0000000000000000000000000000000000000000..4f06b21867447023d428462ccc8f984497992fe6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00296.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00296") +public class BenchmarkTest00296 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00296"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + double stuff = new java.util.Random().nextGaussian(); + String rememberMeKey = Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "Gayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter() + .println("Weak Randomness Test java.util.Random.nextGaussian() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00297.java b/OWASP DATASET/BenchmarkTest00297.java new file mode 100644 index 0000000000000000000000000000000000000000..3c9f399964a90f66a21e189e12925244416715e1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00297.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00297") +public class BenchmarkTest00297 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00297"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + double stuff = new java.util.Random().nextGaussian(); + String rememberMeKey = Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "Gayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter() + .println("Weak Randomness Test java.util.Random.nextGaussian() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00298.java b/OWASP DATASET/BenchmarkTest00298.java new file mode 100644 index 0000000000000000000000000000000000000000..c5e33ea76609ebcb1a807ebcb0ccd8fd4e77330a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00298.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00298") +public class BenchmarkTest00298 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00298"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + int randNumber = new java.util.Random().nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "Inga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt(int) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00299.java b/OWASP DATASET/BenchmarkTest00299.java new file mode 100644 index 0000000000000000000000000000000000000000..03d90e0553a113e572b67f008c2a037993ea5267 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00299.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00299") +public class BenchmarkTest00299 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00299"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00300.java b/OWASP DATASET/BenchmarkTest00300.java new file mode 100644 index 0000000000000000000000000000000000000000..84fa5d0acf2a07b6f97464cfe1e6f8775823bce8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00300.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest00300") +public class BenchmarkTest00300 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00300"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00301.java b/OWASP DATASET/BenchmarkTest00301.java new file mode 100644 index 0000000000000000000000000000000000000000..494c089219e4d34bdca35439299246336f5431f9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00301.java @@ -0,0 +1,63 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00301") +public class BenchmarkTest00301 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "safe!"; + java.util.HashMap map16074 = new java.util.HashMap(); + map16074.put("keyA-16074", "a-Value"); // put some stuff in the collection + map16074.put("keyB-16074", param); // put it in a collection + map16074.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map16074.get("keyB-16074"); // get it back out + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write("Parameter value: " + bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00302.java b/OWASP DATASET/BenchmarkTest00302.java new file mode 100644 index 0000000000000000000000000000000000000000..2207e9c023416e57a4d4560c4a980c68ae04071b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00302.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00302") +public class BenchmarkTest00302 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00302"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00303.java b/OWASP DATASET/BenchmarkTest00303.java new file mode 100644 index 0000000000000000000000000000000000000000..48733d9963ee98b558a731dfe2f02c2b1a89022a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00303.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00303") +public class BenchmarkTest00303 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00303"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ping -c1 "); + args = new String[] {a1, a2, cmd + bar}; + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00304.java b/OWASP DATASET/BenchmarkTest00304.java new file mode 100644 index 0000000000000000000000000000000000000000..93d96d0ff446f9af257bcc1b70f58e53f6cf6838 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00304.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00304") +public class BenchmarkTest00304 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00304"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00305.java b/OWASP DATASET/BenchmarkTest00305.java new file mode 100644 index 0000000000000000000000000000000000000000..a73f460a61702b0f514f521d443b7c79e980f85a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00305.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00305") +public class BenchmarkTest00305 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00305"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + // Chain a bunch of propagators in sequence + String a99928 = param; // assign + StringBuilder b99928 = new StringBuilder(a99928); // stick in stringbuilder + b99928.append(" SafeStuff"); // append some safe content + b99928.replace( + b99928.length() - "Chars".length(), + b99928.length(), + "Chars"); // replace some of the end content + java.util.HashMap map99928 = new java.util.HashMap(); + map99928.put("key99928", b99928.toString()); // put in a collection + String c99928 = (String) map99928.get("key99928"); // get it back out + String d99928 = c99928.substring(0, c99928.length() - 1); // extract most of it + String e99928 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d99928.getBytes()))); // B64 encode and decode it + String f99928 = e99928.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g99928 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g99928); // reflection + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00306.java b/OWASP DATASET/BenchmarkTest00306.java new file mode 100644 index 0000000000000000000000000000000000000000..fd144cb66a4b4ed3bfdf4357e27150a2686e213f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00306.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00306") +public class BenchmarkTest00306 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00306"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00307.java b/OWASP DATASET/BenchmarkTest00307.java new file mode 100644 index 0000000000000000000000000000000000000000..ac83e7438b8234310e66fa02ce9b38f637177047 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00307.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00307") +public class BenchmarkTest00307 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00307"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00308.java b/OWASP DATASET/BenchmarkTest00308.java new file mode 100644 index 0000000000000000000000000000000000000000..d853f94f5236547b19172cd667874aa5aafcdd17 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00308.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00308") +public class BenchmarkTest00308 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00308"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00309.java b/OWASP DATASET/BenchmarkTest00309.java new file mode 100644 index 0000000000000000000000000000000000000000..59e5c1daa68e2c21957e8528b2700bbd18eb667d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00309.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00309") +public class BenchmarkTest00309 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00309"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "safe!"; + java.util.HashMap map92785 = new java.util.HashMap(); + map92785.put("keyA-92785", "a_Value"); // put some stuff in the collection + map92785.put("keyB-92785", param); // put it in a collection + map92785.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map92785.get("keyB-92785"); // get it back out + bar = (String) map92785.get("keyA-92785"); // get safe value back out + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00310.java b/OWASP DATASET/BenchmarkTest00310.java new file mode 100644 index 0000000000000000000000000000000000000000..772d6b1fbb4589056b4539dd8e43dfce5d801413 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00310.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00310") +public class BenchmarkTest00310 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00310"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = + r.exec(cmd + bar, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00311.java b/OWASP DATASET/BenchmarkTest00311.java new file mode 100644 index 0000000000000000000000000000000000000000..ecc05a1f2aab3380437167271ad4e3d0c94525f9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00311.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00311") +public class BenchmarkTest00311 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00311"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + try { + Process p = r.exec(cmd, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00312.java b/OWASP DATASET/BenchmarkTest00312.java new file mode 100644 index 0000000000000000000000000000000000000000..f7f54cf69643d91192c39db09de4a1803a35d7ea --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00312.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00312") +public class BenchmarkTest00312 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00312"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00313.java b/OWASP DATASET/BenchmarkTest00313.java new file mode 100644 index 0000000000000000000000000000000000000000..3e9bb13c85ca419494a77dc2acfc82a2dd05940f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00313.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00313") +public class BenchmarkTest00313 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00313"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + double rand = getNextNumber(numGen); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonatella"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } + + double getNextNumber(java.util.Random generator) { + return generator.nextDouble(); + } +} diff --git a/OWASP DATASET/BenchmarkTest00314.java b/OWASP DATASET/BenchmarkTest00314.java new file mode 100644 index 0000000000000000000000000000000000000000..7e65d233d99ee9c70f2abeb89e214ddd19210239 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00314.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00314") +public class BenchmarkTest00314 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00314"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + double rand = getNextNumber(numGen); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonatella"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } + + double getNextNumber(java.util.Random generator) { + return generator.nextDouble(); + } +} diff --git a/OWASP DATASET/BenchmarkTest00315.java b/OWASP DATASET/BenchmarkTest00315.java new file mode 100644 index 0000000000000000000000000000000000000000..db3dc07d36c4480f4213b3d01f1003ca4fc18d0d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00315.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00315") +public class BenchmarkTest00315 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00315"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "safe!"; + java.util.HashMap map38775 = new java.util.HashMap(); + map38775.put("keyA-38775", "a_Value"); // put some stuff in the collection + map38775.put("keyB-38775", param); // put it in a collection + map38775.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map38775.get("keyB-38775"); // get it back out + bar = (String) map38775.get("keyA-38775"); // get safe value back out + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00316.java b/OWASP DATASET/BenchmarkTest00316.java new file mode 100644 index 0000000000000000000000000000000000000000..f87ed77b58960d47867b923829b897ee5a248363 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00316.java @@ -0,0 +1,132 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00316") +public class BenchmarkTest00316 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00316"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + // Chain a bunch of propagators in sequence + String a78780 = param; // assign + StringBuilder b78780 = new StringBuilder(a78780); // stick in stringbuilder + b78780.append(" SafeStuff"); // append some safe content + b78780.replace( + b78780.length() - "Chars".length(), + b78780.length(), + "Chars"); // replace some of the end content + java.util.HashMap map78780 = new java.util.HashMap(); + map78780.put("key78780", b78780.toString()); // put in a collection + String c78780 = (String) map78780.get("key78780"); // get it back out + String d78780 = c78780.substring(0, c78780.length() - 1); // extract most of it + String e78780 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d78780.getBytes()))); // B64 encode and decode it + String f78780 = e78780.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f78780); // reflection + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00317.java b/OWASP DATASET/BenchmarkTest00317.java new file mode 100644 index 0000000000000000000000000000000000000000..075a00a8dafa74600d30ca74de65f841143f6bb5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00317.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00317") +public class BenchmarkTest00317 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00317"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00318.java b/OWASP DATASET/BenchmarkTest00318.java new file mode 100644 index 0000000000000000000000000000000000000000..4817a4ecefef198a69992b0ade46227dca766347 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00318.java @@ -0,0 +1,131 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00318") +public class BenchmarkTest00318 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00318"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + // Chain a bunch of propagators in sequence + String a30925 = param; // assign + StringBuilder b30925 = new StringBuilder(a30925); // stick in stringbuilder + b30925.append(" SafeStuff"); // append some safe content + b30925.replace( + b30925.length() - "Chars".length(), + b30925.length(), + "Chars"); // replace some of the end content + java.util.HashMap map30925 = new java.util.HashMap(); + map30925.put("key30925", b30925.toString()); // put in a collection + String c30925 = (String) map30925.get("key30925"); // get it back out + String d30925 = c30925.substring(0, c30925.length() - 1); // extract most of it + String e30925 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d30925.getBytes()))); // B64 encode and decode it + String f30925 = e30925.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g30925 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g30925); // reflection + + try { + float rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextFloat(); + String rememberMeKey = + Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeFloyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextFloat() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextFloat() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00319.java b/OWASP DATASET/BenchmarkTest00319.java new file mode 100644 index 0000000000000000000000000000000000000000..2323a15f2f08ca0aab7022f710fb4ef9b0d8d63e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00319.java @@ -0,0 +1,128 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00319") +public class BenchmarkTest00319 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00319"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + try { + int r = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "SafeIngrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00320.java b/OWASP DATASET/BenchmarkTest00320.java new file mode 100644 index 0000000000000000000000000000000000000000..a58734f69ca633a63f9d44855fc7e63e3db1e678 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00320.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00320") +public class BenchmarkTest00320 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00320"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + try { + long l = java.security.SecureRandom.getInstance("SHA1PRNG").nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "SafeLogan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextLong() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextLong() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00321.java b/OWASP DATASET/BenchmarkTest00321.java new file mode 100644 index 0000000000000000000000000000000000000000..f3ad553f8ed34fce28595c041b8de69d9c8003c9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00321.java @@ -0,0 +1,64 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00321") +public class BenchmarkTest00321 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00321"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String^,java.lang.Object) + request.getSession().putValue(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: 10340 saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00322.java b/OWASP DATASET/BenchmarkTest00322.java new file mode 100644 index 0000000000000000000000000000000000000000..8c15e38891b1363f765f95025fba46cc486f3ecf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00322.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00322") +public class BenchmarkTest00322 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00322"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "safe!"; + java.util.HashMap map53101 = new java.util.HashMap(); + map53101.put("keyA-53101", "a_Value"); // put some stuff in the collection + map53101.put("keyB-53101", param); // put it in a collection + map53101.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map53101.get("keyB-53101"); // get it back out + bar = (String) map53101.get("keyA-53101"); // get safe value back out + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00323.java b/OWASP DATASET/BenchmarkTest00323.java new file mode 100644 index 0000000000000000000000000000000000000000..03cabc8e265b54e2b2496a783ef3038f87fa317d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00323.java @@ -0,0 +1,69 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00323") +public class BenchmarkTest00323 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00323"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00324.java b/OWASP DATASET/BenchmarkTest00324.java new file mode 100644 index 0000000000000000000000000000000000000000..16342fd3f0a7b5a22ee561321248ef9aa982b0f8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00324.java @@ -0,0 +1,64 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00324") +public class BenchmarkTest00324 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00324"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00325.java b/OWASP DATASET/BenchmarkTest00325.java new file mode 100644 index 0000000000000000000000000000000000000000..254205fe597d4bcacf0f92d06e81c6b76302811d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00325.java @@ -0,0 +1,64 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00325") +public class BenchmarkTest00325 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00325"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00326.java b/OWASP DATASET/BenchmarkTest00326.java new file mode 100644 index 0000000000000000000000000000000000000000..49baf35107a45f6ca4df7d0b38aafcb8c8ee7485 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00326.java @@ -0,0 +1,69 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00326") +public class BenchmarkTest00326 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00326"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String^,java.lang.Object) + request.getSession().setAttribute(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: '10340' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00327.java b/OWASP DATASET/BenchmarkTest00327.java new file mode 100644 index 0000000000000000000000000000000000000000..4d07cfe5c7f6eb985dcdd0fb5c7b6537336664ad --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00327.java @@ -0,0 +1,66 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00327") +public class BenchmarkTest00327 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00327"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00328.java b/OWASP DATASET/BenchmarkTest00328.java new file mode 100644 index 0000000000000000000000000000000000000000..0e8575bac4be1f0742afe170318fe502be3277c8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00328.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00328") +public class BenchmarkTest00328 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00328"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = connection.prepareCall(sql); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00329.java b/OWASP DATASET/BenchmarkTest00329.java new file mode 100644 index 0000000000000000000000000000000000000000..f4eeac686912c1fb9cdec28c256854c8ea19706e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00329.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00329") +public class BenchmarkTest00329 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00329"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = connection.prepareCall(sql); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00330.java b/OWASP DATASET/BenchmarkTest00330.java new file mode 100644 index 0000000000000000000000000000000000000000..6f2ead7d315eecf784be4c436da9754bd864ce97 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00330.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00330") +public class BenchmarkTest00330 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00330"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + // Chain a bunch of propagators in sequence + String a55109 = param; // assign + StringBuilder b55109 = new StringBuilder(a55109); // stick in stringbuilder + b55109.append(" SafeStuff"); // append some safe content + b55109.replace( + b55109.length() - "Chars".length(), + b55109.length(), + "Chars"); // replace some of the end content + java.util.HashMap map55109 = new java.util.HashMap(); + map55109.put("key55109", b55109.toString()); // put in a collection + String c55109 = (String) map55109.get("key55109"); // get it back out + String d55109 = c55109.substring(0, c55109.length() - 1); // extract most of it + String e55109 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d55109.getBytes()))); // B64 encode and decode it + String f55109 = e55109.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g55109 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g55109); // reflection + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = connection.prepareCall(sql); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00331.java b/OWASP DATASET/BenchmarkTest00331.java new file mode 100644 index 0000000000000000000000000000000000000000..d52c5e8d0a103cb4fd4cd15393ebb94ac3c1f4b0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00331.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00331") +public class BenchmarkTest00331 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00331"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "safe!"; + java.util.HashMap map59781 = new java.util.HashMap(); + map59781.put("keyA-59781", "a_Value"); // put some stuff in the collection + map59781.put("keyB-59781", param); // put it in a collection + map59781.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map59781.get("keyB-59781"); // get it back out + bar = (String) map59781.get("keyA-59781"); // get safe value back out + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = connection.prepareStatement(sql); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00332.java b/OWASP DATASET/BenchmarkTest00332.java new file mode 100644 index 0000000000000000000000000000000000000000..4fd8885bbc30e4fe1974dcdc396653b04e5ff910 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00332.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00332") +public class BenchmarkTest00332 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00332"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + // Chain a bunch of propagators in sequence + String a40477 = param; // assign + StringBuilder b40477 = new StringBuilder(a40477); // stick in stringbuilder + b40477.append(" SafeStuff"); // append some safe content + b40477.replace( + b40477.length() - "Chars".length(), + b40477.length(), + "Chars"); // replace some of the end content + java.util.HashMap map40477 = new java.util.HashMap(); + map40477.put("key40477", b40477.toString()); // put in a collection + String c40477 = (String) map40477.get("key40477"); // get it back out + String d40477 = c40477.substring(0, c40477.length() - 1); // extract most of it + String e40477 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d40477.getBytes()))); // B64 encode and decode it + String f40477 = e40477.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g40477 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g40477); // reflection + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = connection.prepareStatement(sql); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00333.java b/OWASP DATASET/BenchmarkTest00333.java new file mode 100644 index 0000000000000000000000000000000000000000..824bb8821f9fd109a3dcaf6d41638dd00e8d0a39 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00333.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00333") +public class BenchmarkTest00333 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00333"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = connection.prepareStatement(sql); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00334.java b/OWASP DATASET/BenchmarkTest00334.java new file mode 100644 index 0000000000000000000000000000000000000000..f4719854a49d9820d8d53d2ae24c8d19c630fa52 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00334.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00334") +public class BenchmarkTest00334 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00334"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + // Chain a bunch of propagators in sequence + String a30608 = param; // assign + StringBuilder b30608 = new StringBuilder(a30608); // stick in stringbuilder + b30608.append(" SafeStuff"); // append some safe content + b30608.replace( + b30608.length() - "Chars".length(), + b30608.length(), + "Chars"); // replace some of the end content + java.util.HashMap map30608 = new java.util.HashMap(); + map30608.put("key30608", b30608.toString()); // put in a collection + String c30608 = (String) map30608.get("key30608"); // get it back out + String d30608 = c30608.substring(0, c30608.length() - 1); // extract most of it + String e30608 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d30608.getBytes()))); // B64 encode and decode it + String f30608 = e30608.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g30608 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g30608); // reflection + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00335.java b/OWASP DATASET/BenchmarkTest00335.java new file mode 100644 index 0000000000000000000000000000000000000000..20cbf1054092d16d8b9fa5dd45d6313fdb614997 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00335.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00335") +public class BenchmarkTest00335 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00335"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, new int[] {1, 2}); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00336.java b/OWASP DATASET/BenchmarkTest00336.java new file mode 100644 index 0000000000000000000000000000000000000000..a82ade6005801007db2c94e01726014aa6859f81 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00336.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00336") +public class BenchmarkTest00336 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00336"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // Long results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForLong(sql); + Long results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Long.class); + response.getWriter().println("Your results are: " + String.valueOf(results)); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00337.java b/OWASP DATASET/BenchmarkTest00337.java new file mode 100644 index 0000000000000000000000000000000000000000..dc77a80c7d26d767d285fd4a2765ddc4251fe565 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00337.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00337") +public class BenchmarkTest00337 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00337"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + String sql = + "SELECT TOP 1 USERNAME from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + Object results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, new Object[] {}, String.class); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(results.toString())); + // System.out.println(results.toString()); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00338.java b/OWASP DATASET/BenchmarkTest00338.java new file mode 100644 index 0000000000000000000000000000000000000000..8c8d683c2e58671c1a6c9773c3f137956e171886 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00338.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00338") +public class BenchmarkTest00338 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00338"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + String sql = + "SELECT TOP 1 USERNAME from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + Object results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, new Object[] {}, String.class); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(results.toString())); + // System.out.println(results.toString()); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00339.java b/OWASP DATASET/BenchmarkTest00339.java new file mode 100644 index 0000000000000000000000000000000000000000..b68d7017712a3139f772a1e25b95e77e0f5165c8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00339.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00339") +public class BenchmarkTest00339 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00339"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + org.springframework.jdbc.support.rowset.SqlRowSet results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForRowSet(sql); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + while (results.next()) { + response.getWriter() + .println( + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(results.getString("USERNAME")) + + " "); + // System.out.println(results.getString("USERNAME")); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00340.java b/OWASP DATASET/BenchmarkTest00340.java new file mode 100644 index 0000000000000000000000000000000000000000..53ff72bcb007d9bd795519b3b1ebb88b0dc91912 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00340.java @@ -0,0 +1,90 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00340") +public class BenchmarkTest00340 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00340"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00341.java b/OWASP DATASET/BenchmarkTest00341.java new file mode 100644 index 0000000000000000000000000000000000000000..7f071f2cf7bf53dc358ca499287f13b40f637185 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00341.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00341") +public class BenchmarkTest00341 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00341"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00342.java b/OWASP DATASET/BenchmarkTest00342.java new file mode 100644 index 0000000000000000000000000000000000000000..172e6cf83528fa901720dc1e3a1fcf2477246510 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00342.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00342") +public class BenchmarkTest00342 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00342"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new String[] {"username", "password"}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00343.java b/OWASP DATASET/BenchmarkTest00343.java new file mode 100644 index 0000000000000000000000000000000000000000..d472983b4b79985c0feb85c481a38c0b957e8a1e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00343.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00343") +public class BenchmarkTest00343 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00343"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new String[] {"username", "password"}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00344.java b/OWASP DATASET/BenchmarkTest00344.java new file mode 100644 index 0000000000000000000000000000000000000000..105452493733210569dd9b0e754b2834c33aa644 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00344.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00344") +public class BenchmarkTest00344 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest00344"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + java.sql.ResultSet rs = statement.executeQuery(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00345.java b/OWASP DATASET/BenchmarkTest00345.java new file mode 100644 index 0000000000000000000000000000000000000000..10055500d73061e4c292bc0e0ffac2f4618385dd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00345.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00345") +public class BenchmarkTest00345 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.io.InputStream param = request.getInputStream(); + + java.io.InputStream bar = param; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "AES/CCM/NoPadding", java.security.Security.getProvider("BC")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00346.java b/OWASP DATASET/BenchmarkTest00346.java new file mode 100644 index 0000000000000000000000000000000000000000..46bf8989dbae107f65450ef579ab9a564e49156b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00346.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00346") +public class BenchmarkTest00346 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.io.InputStream param = request.getInputStream(); + + java.io.InputStream bar = param; + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("SHA1", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00347.java b/OWASP DATASET/BenchmarkTest00347.java new file mode 100644 index 0000000000000000000000000000000000000000..4a855bab5d953fab874dca82e30e5c7431d210f0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00347.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00347") +public class BenchmarkTest00347 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.io.InputStream param = request.getInputStream(); + + java.io.InputStream bar = param; + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00348.java b/OWASP DATASET/BenchmarkTest00348.java new file mode 100644 index 0000000000000000000000000000000000000000..15c3af1d257387f6d5e6ad6fef49d9b2aa56b564 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00348.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest00348") +public class BenchmarkTest00348 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.io.InputStream param = request.getInputStream(); + + java.io.InputStream bar = param; + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00349.java b/OWASP DATASET/BenchmarkTest00349.java new file mode 100644 index 0000000000000000000000000000000000000000..ec0e26b1b757b4002fc46d0ed240a4c950c82a8f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00349.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00349") +public class BenchmarkTest00349 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.io.InputStream param = request.getInputStream(); + + java.io.InputStream bar = param; + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00350.java b/OWASP DATASET/BenchmarkTest00350.java new file mode 100644 index 0000000000000000000000000000000000000000..bd9845395cf7abb00319cbdc5b4219ab92b745e6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00350.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00350") +public class BenchmarkTest00350 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00350"); + if (param == null) param = ""; + + String bar = "safe!"; + java.util.HashMap map51742 = new java.util.HashMap(); + map51742.put("keyA-51742", "a_Value"); // put some stuff in the collection + map51742.put("keyB-51742", param); // put it in a collection + map51742.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map51742.get("keyB-51742"); // get it back out + bar = (String) map51742.get("keyA-51742"); // get safe value back out + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = org.owasp.benchmark.helpers.Utils.getCipher(); + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00351.java b/OWASP DATASET/BenchmarkTest00351.java new file mode 100644 index 0000000000000000000000000000000000000000..916d53f6e423d363f71093c24f7812b967f7ad2e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00351.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00351") +public class BenchmarkTest00351 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00351"); + if (param == null) param = ""; + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = org.owasp.benchmark.helpers.Utils.getCipher(); + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00352.java b/OWASP DATASET/BenchmarkTest00352.java new file mode 100644 index 0000000000000000000000000000000000000000..d63e56161f7d8a0362e616c6b484ed1a02fc1dd6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00352.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00352") +public class BenchmarkTest00352 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00352"); + if (param == null) param = ""; + + // Chain a bunch of propagators in sequence + String a98424 = param; // assign + StringBuilder b98424 = new StringBuilder(a98424); // stick in stringbuilder + b98424.append(" SafeStuff"); // append some safe content + b98424.replace( + b98424.length() - "Chars".length(), + b98424.length(), + "Chars"); // replace some of the end content + java.util.HashMap map98424 = new java.util.HashMap(); + map98424.put("key98424", b98424.toString()); // put in a collection + String c98424 = (String) map98424.get("key98424"); // get it back out + String d98424 = c98424.substring(0, c98424.length() - 1); // extract most of it + String e98424 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d98424.getBytes()))); // B64 encode and decode it + String f98424 = e98424.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f98424); // reflection + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "AES/CCM/NoPadding", java.security.Security.getProvider("BC")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00353.java b/OWASP DATASET/BenchmarkTest00353.java new file mode 100644 index 0000000000000000000000000000000000000000..b1223a47b7c338678ac6b46f8bf749e318d2e13a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00353.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00353") +public class BenchmarkTest00353 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00353"); + if (param == null) param = ""; + + String bar = "safe!"; + java.util.HashMap map13001 = new java.util.HashMap(); + map13001.put("keyA-13001", "a_Value"); // put some stuff in the collection + map13001.put("keyB-13001", param); // put it in a collection + map13001.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map13001.get("keyB-13001"); // get it back out + bar = (String) map13001.get("keyA-13001"); // get safe value back out + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "AES/CCM/NoPadding", java.security.Security.getProvider("BC")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00354.java b/OWASP DATASET/BenchmarkTest00354.java new file mode 100644 index 0000000000000000000000000000000000000000..89b7102653e63b0aa81f40a612bf9c3d997db419 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00354.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00354") +public class BenchmarkTest00354 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00354"); + if (param == null) param = ""; + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00355.java b/OWASP DATASET/BenchmarkTest00355.java new file mode 100644 index 0000000000000000000000000000000000000000..b1a12e58a2a8f656db6d32d1722ffce306e0da5b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00355.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00355") +public class BenchmarkTest00355 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00355"); + if (param == null) param = ""; + + // Chain a bunch of propagators in sequence + String a85622 = param; // assign + StringBuilder b85622 = new StringBuilder(a85622); // stick in stringbuilder + b85622.append(" SafeStuff"); // append some safe content + b85622.replace( + b85622.length() - "Chars".length(), + b85622.length(), + "Chars"); // replace some of the end content + java.util.HashMap map85622 = new java.util.HashMap(); + map85622.put("key85622", b85622.toString()); // put in a collection + String c85622 = (String) map85622.get("key85622"); // get it back out + String d85622 = c85622.substring(0, c85622.length() - 1); // extract most of it + String e85622 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d85622.getBytes()))); // B64 encode and decode it + String f85622 = e85622.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f85622); // reflection + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00356.java b/OWASP DATASET/BenchmarkTest00356.java new file mode 100644 index 0000000000000000000000000000000000000000..e0a41e2d7178715724e363e24698054127ff6e0e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00356.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00356") +public class BenchmarkTest00356 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00356"); + if (param == null) param = ""; + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00357.java b/OWASP DATASET/BenchmarkTest00357.java new file mode 100644 index 0000000000000000000000000000000000000000..ec5ff534ab52700a00d3c97ca3f4ff66c65b30ac --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00357.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00357") +public class BenchmarkTest00357 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00357"); + if (param == null) param = ""; + + String bar = param; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + // java.security.SecureRandom random = new java.security.SecureRandom(); + // byte[] iv = random.generateSeed(16); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg2", "AES/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00358.java b/OWASP DATASET/BenchmarkTest00358.java new file mode 100644 index 0000000000000000000000000000000000000000..a2da251ff3304f9ccd17b545bb12328928ccc90f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00358.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00358") +public class BenchmarkTest00358 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00358"); + if (param == null) param = ""; + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + // java.security.SecureRandom random = new java.security.SecureRandom(); + // byte[] iv = random.generateSeed(16); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg2", "AES/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00359.java b/OWASP DATASET/BenchmarkTest00359.java new file mode 100644 index 0000000000000000000000000000000000000000..c98ad87389f0a9dc0d4b9ede8f9f8d7408c071ff --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00359.java @@ -0,0 +1,69 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00359") +public class BenchmarkTest00359 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00359"); + if (param == null) param = ""; + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + java.io.File fileTarget = new java.io.File(bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00360.java b/OWASP DATASET/BenchmarkTest00360.java new file mode 100644 index 0000000000000000000000000000000000000000..f2cc4b8f4dd2a53398618c9bed442835045c2ecc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00360.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00360") +public class BenchmarkTest00360 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00360"); + if (param == null) param = ""; + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(new java.io.File(fileName)); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting FileInputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00361.java b/OWASP DATASET/BenchmarkTest00361.java new file mode 100644 index 0000000000000000000000000000000000000000..5890cf6f9ef32fcb7514623e19f1d9e3c8333c31 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00361.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00361") +public class BenchmarkTest00361 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00361"); + if (param == null) param = ""; + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(fileName); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00362.java b/OWASP DATASET/BenchmarkTest00362.java new file mode 100644 index 0000000000000000000000000000000000000000..70edce338d1f04258614bcfb983ac27e1ded0d32 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00362.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00362") +public class BenchmarkTest00362 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00362"); + if (param == null) param = ""; + + String bar = param; + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName)); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00363.java b/OWASP DATASET/BenchmarkTest00363.java new file mode 100644 index 0000000000000000000000000000000000000000..ad30df8903104123652ef964c203a98880b71473 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00363.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00363") +public class BenchmarkTest00363 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00363"); + if (param == null) param = ""; + + String bar = param; + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + try ( + // Create the file first so the test won't throw an exception if it doesn't exist. + // Note: Don't actually do this because this method signature could cause a tool to find + // THIS file constructor + // as a vuln, rather than the File signature we are trying to actually test. + // If necessary, just run the benchmark twice. The 1st run should create all the necessary + // files. + // new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar).createNewFile(); + + java.io.FileOutputStream fos = + new java.io.FileOutputStream(new java.io.FileInputStream(fileName).getFD()); ) { + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00364.java b/OWASP DATASET/BenchmarkTest00364.java new file mode 100644 index 0000000000000000000000000000000000000000..fab65d32b438802d9d8fc0809387365826caabfd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00364.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00364") +public class BenchmarkTest00364 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00364"); + if (param == null) param = ""; + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName, false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00365.java b/OWASP DATASET/BenchmarkTest00365.java new file mode 100644 index 0000000000000000000000000000000000000000..fb8521a8b58f046e65f24452b3bcb51ccbdea48a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00365.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00365") +public class BenchmarkTest00365 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00365"); + if (param == null) param = ""; + + String bar = "safe!"; + java.util.HashMap map10106 = new java.util.HashMap(); + map10106.put("keyA-10106", "a_Value"); // put some stuff in the collection + map10106.put("keyB-10106", param); // put it in a collection + map10106.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map10106.get("keyB-10106"); // get it back out + bar = (String) map10106.get("keyA-10106"); // get safe value back out + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + java.io.InputStream is = null; + + try { + java.nio.file.Path path = java.nio.file.Paths.get(fileName); + is = java.nio.file.Files.newInputStream(path, java.nio.file.StandardOpenOption.READ); + byte[] b = new byte[1000]; + int size = is.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + is.close(); + } catch (Exception e) { + System.out.println("Couldn't open InputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting InputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (is != null) { + try { + is.close(); + is = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00366.java b/OWASP DATASET/BenchmarkTest00366.java new file mode 100644 index 0000000000000000000000000000000000000000..ad7b0bc7b0566ad0f3a0ef3b1a1ed32997b0c991 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00366.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00366") +public class BenchmarkTest00366 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00366"); + if (param == null) param = ""; + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + java.io.InputStream is = null; + + try { + java.nio.file.Path path = java.nio.file.Paths.get(fileName); + is = java.nio.file.Files.newInputStream(path, java.nio.file.StandardOpenOption.READ); + byte[] b = new byte[1000]; + int size = is.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + is.close(); + } catch (Exception e) { + System.out.println("Couldn't open InputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting InputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (is != null) { + try { + is.close(); + is = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00367.java b/OWASP DATASET/BenchmarkTest00367.java new file mode 100644 index 0000000000000000000000000000000000000000..5e765997fcb730bc51ea84b8908d7c54d1434376 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00367.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest00367") +public class BenchmarkTest00367 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00367"); + if (param == null) param = ""; + + // Chain a bunch of propagators in sequence + String a12849 = param; // assign + StringBuilder b12849 = new StringBuilder(a12849); // stick in stringbuilder + b12849.append(" SafeStuff"); // append some safe content + b12849.replace( + b12849.length() - "Chars".length(), + b12849.length(), + "Chars"); // replace some of the end content + java.util.HashMap map12849 = new java.util.HashMap(); + map12849.put("key12849", b12849.toString()); // put in a collection + String c12849 = (String) map12849.get("key12849"); // get it back out + String d12849 = c12849.substring(0, c12849.length() - 1); // extract most of it + String e12849 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d12849.getBytes()))); // B64 encode and decode it + String f12849 = e12849.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g12849 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g12849); // reflection + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + bar + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + + javax.naming.directory.DirContext ctx = ads.getDirContext(); + javax.naming.directory.InitialDirContext idc = + (javax.naming.directory.InitialDirContext) ctx; + boolean found = false; + javax.naming.NamingEnumeration results = + idc.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00368.java b/OWASP DATASET/BenchmarkTest00368.java new file mode 100644 index 0000000000000000000000000000000000000000..c4c3bff5a97ceebf69f2c1d8fed7af7de6f60ece --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00368.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00368") +public class BenchmarkTest00368 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00368"); + if (param == null) param = ""; + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + double value = java.lang.Math.random(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Doug"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + response.getWriter().println("Weak Randomness Test java.lang.Math.random() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00369.java b/OWASP DATASET/BenchmarkTest00369.java new file mode 100644 index 0000000000000000000000000000000000000000..a5df724ed6f1518f3ddd13d290b671af9064c9f4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00369.java @@ -0,0 +1,100 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00369") +public class BenchmarkTest00369 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00369"); + if (param == null) param = ""; + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + double value = java.lang.Math.random(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Doug"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + response.getWriter().println("Weak Randomness Test java.lang.Math.random() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00370.java b/OWASP DATASET/BenchmarkTest00370.java new file mode 100644 index 0000000000000000000000000000000000000000..5694998c1a9dd42745ee918585dd1017a9778e05 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00370.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00370") +public class BenchmarkTest00370 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00370"); + if (param == null) param = ""; + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("sha-384", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("sha-384", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00371.java b/OWASP DATASET/BenchmarkTest00371.java new file mode 100644 index 0000000000000000000000000000000000000000..1a5f46094197ec9928fbdac41111e740e542f9cb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00371.java @@ -0,0 +1,107 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00371") +public class BenchmarkTest00371 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00371"); + if (param == null) param = ""; + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00372.java b/OWASP DATASET/BenchmarkTest00372.java new file mode 100644 index 0000000000000000000000000000000000000000..466feff035f1066566dffb29552da0c6b71ff7f4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00372.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00372") +public class BenchmarkTest00372 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00372"); + if (param == null) param = ""; + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00373.java b/OWASP DATASET/BenchmarkTest00373.java new file mode 100644 index 0000000000000000000000000000000000000000..b21f7dd68bc9e23d8ff663aeb81f82cf7ec3365d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00373.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00373") +public class BenchmarkTest00373 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00373"); + if (param == null) param = ""; + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-256"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00374.java b/OWASP DATASET/BenchmarkTest00374.java new file mode 100644 index 0000000000000000000000000000000000000000..1aa66a8b6639f581e1413f790245a1d3eb6370bc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00374.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00374") +public class BenchmarkTest00374 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00374"); + if (param == null) param = ""; + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00375.java b/OWASP DATASET/BenchmarkTest00375.java new file mode 100644 index 0000000000000000000000000000000000000000..d532f17f8535f7da4d97de72cae960b17586b0d7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00375.java @@ -0,0 +1,53 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00375") +public class BenchmarkTest00375 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00375"); + if (param == null) param = ""; + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(java.util.Locale.US, bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00376.java b/OWASP DATASET/BenchmarkTest00376.java new file mode 100644 index 0000000000000000000000000000000000000000..94b41e15bd2f8928f9f438cc00f5525d7891dd5e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00376.java @@ -0,0 +1,57 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00376") +public class BenchmarkTest00376 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00376"); + if (param == null) param = ""; + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().format("Formatted like: %1$s and %2$s.", obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00377.java b/OWASP DATASET/BenchmarkTest00377.java new file mode 100644 index 0000000000000000000000000000000000000000..75ce7241ebb5ffc5ba40248ce650a78ed3b035a1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00377.java @@ -0,0 +1,62 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00377") +public class BenchmarkTest00377 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00377"); + if (param == null) param = ""; + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().format("Formatted like: %1$s and %2$s.", obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00378.java b/OWASP DATASET/BenchmarkTest00378.java new file mode 100644 index 0000000000000000000000000000000000000000..961b29bdb8f896ef8e9c8cd2d95ca91c40864008 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00378.java @@ -0,0 +1,53 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00378") +public class BenchmarkTest00378 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00378"); + if (param == null) param = ""; + + StringBuilder sbxyz85125 = new StringBuilder(param); + String bar = sbxyz85125.append("_SafeStuff").toString(); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00379.java b/OWASP DATASET/BenchmarkTest00379.java new file mode 100644 index 0000000000000000000000000000000000000000..b3279cdf79b4fe07ec304f3d2a3619f570507c3e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00379.java @@ -0,0 +1,72 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00379") +public class BenchmarkTest00379 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00379"); + if (param == null) param = ""; + + // Chain a bunch of propagators in sequence + String a75704 = param; // assign + StringBuilder b75704 = new StringBuilder(a75704); // stick in stringbuilder + b75704.append(" SafeStuff"); // append some safe content + b75704.replace( + b75704.length() - "Chars".length(), + b75704.length(), + "Chars"); // replace some of the end content + java.util.HashMap map75704 = new java.util.HashMap(); + map75704.put("key75704", b75704.toString()); // put in a collection + String c75704 = (String) map75704.get("key75704"); // get it back out + String d75704 = c75704.substring(0, c75704.length() - 1); // extract most of it + String e75704 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d75704.getBytes()))); // B64 encode and decode it + String f75704 = e75704.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g75704 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g75704); // reflection + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar.toCharArray()); + } +} diff --git a/OWASP DATASET/BenchmarkTest00380.java b/OWASP DATASET/BenchmarkTest00380.java new file mode 100644 index 0000000000000000000000000000000000000000..22c404e4a7be0e13c26cb2d2febfcf9498573192 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00380.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00380") +public class BenchmarkTest00380 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00380"); + if (param == null) param = ""; + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00381.java b/OWASP DATASET/BenchmarkTest00381.java new file mode 100644 index 0000000000000000000000000000000000000000..5c365acfd879404a3c58d1aff4165225091aa44c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00381.java @@ -0,0 +1,52 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00381") +public class BenchmarkTest00381 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00381"); + if (param == null) param = ""; + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00382.java b/OWASP DATASET/BenchmarkTest00382.java new file mode 100644 index 0000000000000000000000000000000000000000..e78fb70326be92b940ba834196d6fee5f26b09df --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00382.java @@ -0,0 +1,62 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00382") +public class BenchmarkTest00382 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00382"); + if (param == null) param = ""; + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(java.util.Locale.US, bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00383.java b/OWASP DATASET/BenchmarkTest00383.java new file mode 100644 index 0000000000000000000000000000000000000000..bff684639a5a8e8142cccd41a696b99c8a86a231 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00383.java @@ -0,0 +1,72 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00383") +public class BenchmarkTest00383 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00383"); + if (param == null) param = ""; + + // Chain a bunch of propagators in sequence + String a2196 = param; // assign + StringBuilder b2196 = new StringBuilder(a2196); // stick in stringbuilder + b2196.append(" SafeStuff"); // append some safe content + b2196.replace( + b2196.length() - "Chars".length(), + b2196.length(), + "Chars"); // replace some of the end content + java.util.HashMap map2196 = new java.util.HashMap(); + map2196.put("key2196", b2196.toString()); // put in a collection + String c2196 = (String) map2196.get("key2196"); // get it back out + String d2196 = c2196.substring(0, c2196.length() - 1); // extract most of it + String e2196 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d2196.getBytes()))); // B64 encode and decode it + String f2196 = e2196.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f2196); // reflection + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(java.util.Locale.US, bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00384.java b/OWASP DATASET/BenchmarkTest00384.java new file mode 100644 index 0000000000000000000000000000000000000000..241d3d938fa7d6e0614a2a11659fa4cf507a5b3a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00384.java @@ -0,0 +1,54 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00384") +public class BenchmarkTest00384 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00384"); + if (param == null) param = ""; + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(java.util.Locale.US, bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00385.java b/OWASP DATASET/BenchmarkTest00385.java new file mode 100644 index 0000000000000000000000000000000000000000..04268892c7ba800e30e276cae02f75bcff642170 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00385.java @@ -0,0 +1,72 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00385") +public class BenchmarkTest00385 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00385"); + if (param == null) param = ""; + + // Chain a bunch of propagators in sequence + String a21475 = param; // assign + StringBuilder b21475 = new StringBuilder(a21475); // stick in stringbuilder + b21475.append(" SafeStuff"); // append some safe content + b21475.replace( + b21475.length() - "Chars".length(), + b21475.length(), + "Chars"); // replace some of the end content + java.util.HashMap map21475 = new java.util.HashMap(); + map21475.put("key21475", b21475.toString()); // put in a collection + String c21475 = (String) map21475.get("key21475"); // get it back out + String d21475 = c21475.substring(0, c21475.length() - 1); // extract most of it + String e21475 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d21475.getBytes()))); // B64 encode and decode it + String f21475 = e21475.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f21475); // reflection + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {bar, "b"}; + response.getWriter().printf("Formatted like: %1$s and %2$s.", obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00386.java b/OWASP DATASET/BenchmarkTest00386.java new file mode 100644 index 0000000000000000000000000000000000000000..86171a88d6e9e1348ab4dc923c61c6a384dcd2c6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00386.java @@ -0,0 +1,58 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00386") +public class BenchmarkTest00386 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00386"); + if (param == null) param = ""; + + String bar = "safe!"; + java.util.HashMap map8057 = new java.util.HashMap(); + map8057.put("keyA-8057", "a_Value"); // put some stuff in the collection + map8057.put("keyB-8057", param); // put it in a collection + map8057.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map8057.get("keyB-8057"); // get it back out + bar = (String) map8057.get("keyA-8057"); // get safe value back out + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {bar, "b"}; + response.getWriter().printf("Formatted like: %1$s and %2$s.", obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00387.java b/OWASP DATASET/BenchmarkTest00387.java new file mode 100644 index 0000000000000000000000000000000000000000..c8f85343d08064c0250db60511554c5b8421af10 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00387.java @@ -0,0 +1,56 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00387") +public class BenchmarkTest00387 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00387"); + if (param == null) param = ""; + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar.toCharArray()); + } +} diff --git a/OWASP DATASET/BenchmarkTest00388.java b/OWASP DATASET/BenchmarkTest00388.java new file mode 100644 index 0000000000000000000000000000000000000000..b8bb389b41d7f6e1063d33445b57816fee1c2ace --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00388.java @@ -0,0 +1,52 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00388") +public class BenchmarkTest00388 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00388"); + if (param == null) param = ""; + + StringBuilder sbxyz30382 = new StringBuilder(param); + String bar = sbxyz30382.append("_SafeStuff").toString(); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar.toCharArray()); + } +} diff --git a/OWASP DATASET/BenchmarkTest00389.java b/OWASP DATASET/BenchmarkTest00389.java new file mode 100644 index 0000000000000000000000000000000000000000..7b99d89ce171c46e36f825f2db5e7b74a1ca1246 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00389.java @@ -0,0 +1,51 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00389") +public class BenchmarkTest00389 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00389"); + if (param == null) param = ""; + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00390.java b/OWASP DATASET/BenchmarkTest00390.java new file mode 100644 index 0000000000000000000000000000000000000000..ae95854694781e0b60fcfee15f8e81e2c3ef7f6f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00390.java @@ -0,0 +1,58 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00390") +public class BenchmarkTest00390 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00390"); + if (param == null) param = ""; + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00391.java b/OWASP DATASET/BenchmarkTest00391.java new file mode 100644 index 0000000000000000000000000000000000000000..6fea39c60a8e6a79695748288af029d53b447d2d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00391.java @@ -0,0 +1,51 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00391") +public class BenchmarkTest00391 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00391"); + if (param == null) param = ""; + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00392.java b/OWASP DATASET/BenchmarkTest00392.java new file mode 100644 index 0000000000000000000000000000000000000000..43a339449cb6ce527f93e6417cefc2655e662d33 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00392.java @@ -0,0 +1,59 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00392") +public class BenchmarkTest00392 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00392"); + if (param == null) param = ""; + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz38384 = new StringBuilder(param); + bar = sbxyz38384.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar.toCharArray(), 0, length); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00393.java b/OWASP DATASET/BenchmarkTest00393.java new file mode 100644 index 0000000000000000000000000000000000000000..f16359f1246f0e6b3ce497b15a8c5467d79dfa12 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00393.java @@ -0,0 +1,56 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00393") +public class BenchmarkTest00393 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00393"); + if (param == null) param = ""; + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00394.java b/OWASP DATASET/BenchmarkTest00394.java new file mode 100644 index 0000000000000000000000000000000000000000..d787192a3ca84dfb3f47487dfa23d6125dd005dc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00394.java @@ -0,0 +1,65 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00394") +public class BenchmarkTest00394 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00394"); + if (param == null) param = ""; + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar, 0, length); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00395.java b/OWASP DATASET/BenchmarkTest00395.java new file mode 100644 index 0000000000000000000000000000000000000000..6fcc6512503ab52188943952195a51725313a6a1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00395.java @@ -0,0 +1,56 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00395") +public class BenchmarkTest00395 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00395"); + if (param == null) param = ""; + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar, 0, length); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00396.java b/OWASP DATASET/BenchmarkTest00396.java new file mode 100644 index 0000000000000000000000000000000000000000..06054c3ea4c6bd038e3c95b5185fef97e1deea4b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00396.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00396") +public class BenchmarkTest00396 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00396"); + if (param == null) param = ""; + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + String a1 = ""; + String a2 = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + } else { + a1 = "sh"; + a2 = "-c"; + } + String[] args = {a1, a2, "echo " + bar}; + + ProcessBuilder pb = new ProcessBuilder(); + + pb.command(args); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00397.java b/OWASP DATASET/BenchmarkTest00397.java new file mode 100644 index 0000000000000000000000000000000000000000..bdfb7af5cf7bab25685d18f35b553f28d1d98263 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00397.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00397") +public class BenchmarkTest00397 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00397"); + if (param == null) param = ""; + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + byte[] bytes = new byte[10]; + new java.util.Random().nextBytes(bytes); + String rememberMeKey = org.owasp.esapi.ESAPI.encoder().encodeForBase64(bytes, true); + + String user = "Byron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextBytes() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00398.java b/OWASP DATASET/BenchmarkTest00398.java new file mode 100644 index 0000000000000000000000000000000000000000..024a017deb2c92dabae6afd3464e04233ed00f91 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00398.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00398") +public class BenchmarkTest00398 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00398"); + if (param == null) param = ""; + + String bar = "safe!"; + java.util.HashMap map43631 = new java.util.HashMap(); + map43631.put("keyA-43631", "a_Value"); // put some stuff in the collection + map43631.put("keyB-43631", param); // put it in a collection + map43631.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map43631.get("keyB-43631"); // get it back out + bar = (String) map43631.get("keyA-43631"); // get safe value back out + + double value = new java.util.Random().nextDouble(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Donna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextDouble() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00399.java b/OWASP DATASET/BenchmarkTest00399.java new file mode 100644 index 0000000000000000000000000000000000000000..3f4673ec74bc2c30baca9dc2f8648b98183cc6f5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00399.java @@ -0,0 +1,118 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00399") +public class BenchmarkTest00399 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00399"); + if (param == null) param = ""; + + // Chain a bunch of propagators in sequence + String a78565 = param; // assign + StringBuilder b78565 = new StringBuilder(a78565); // stick in stringbuilder + b78565.append(" SafeStuff"); // append some safe content + b78565.replace( + b78565.length() - "Chars".length(), + b78565.length(), + "Chars"); // replace some of the end content + java.util.HashMap map78565 = new java.util.HashMap(); + map78565.put("key78565", b78565.toString()); // put in a collection + String c78565 = (String) map78565.get("key78565"); // get it back out + String d78565 = c78565.substring(0, c78565.length() - 1); // extract most of it + String e78565 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d78565.getBytes()))); // B64 encode and decode it + String f78565 = e78565.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g78565 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g78565); // reflection + + double value = new java.util.Random().nextDouble(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Donna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextDouble() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00400.java b/OWASP DATASET/BenchmarkTest00400.java new file mode 100644 index 0000000000000000000000000000000000000000..52644ac87927a00ad7fed0aaf59d89f5264d9ddd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00400.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00400") +public class BenchmarkTest00400 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00400"); + if (param == null) param = ""; + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + float rand = new java.util.Random().nextFloat(); + String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "Floyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00401.java b/OWASP DATASET/BenchmarkTest00401.java new file mode 100644 index 0000000000000000000000000000000000000000..7d584e38c80b3922dc0896553d2a642eb1f60135 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00401.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00401") +public class BenchmarkTest00401 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00401"); + if (param == null) param = ""; + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + int randNumber = new java.util.Random().nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "Inga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt(int) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00402.java b/OWASP DATASET/BenchmarkTest00402.java new file mode 100644 index 0000000000000000000000000000000000000000..de2327239214952d0ef03b3bf4cab1bd240011cf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00402.java @@ -0,0 +1,100 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-00/BenchmarkTest00402") +public class BenchmarkTest00402 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00402"); + if (param == null) param = ""; + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz11630 = new StringBuilder(param); + bar = sbxyz11630.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00403.java b/OWASP DATASET/BenchmarkTest00403.java new file mode 100644 index 0000000000000000000000000000000000000000..448abc6f7ab9bb1d5294192fa3580ea77030e6e0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00403.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest00403") +public class BenchmarkTest00403 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00403"); + if (param == null) param = ""; + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00404.java b/OWASP DATASET/BenchmarkTest00404.java new file mode 100644 index 0000000000000000000000000000000000000000..58105bbd570e85b34484cb020b1b9375e9942a0e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00404.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest00404") +public class BenchmarkTest00404 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00404"); + if (param == null) param = ""; + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00405.java b/OWASP DATASET/BenchmarkTest00405.java new file mode 100644 index 0000000000000000000000000000000000000000..21069fd2b3e6767c4e48b498da0825cc8c422467 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00405.java @@ -0,0 +1,80 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest00405") +public class BenchmarkTest00405 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00405"); + if (param == null) param = ""; + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00406.java b/OWASP DATASET/BenchmarkTest00406.java new file mode 100644 index 0000000000000000000000000000000000000000..b74f6deed30caf22da2d5cd9624130f86a8420a8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00406.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00406") +public class BenchmarkTest00406 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00406"); + if (param == null) param = ""; + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ping -c1 "); + args = new String[] {a1, a2, cmd + bar}; + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00407.java b/OWASP DATASET/BenchmarkTest00407.java new file mode 100644 index 0000000000000000000000000000000000000000..faa3eec93e91c1e9e70f36dd48cfa68aba549c8a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00407.java @@ -0,0 +1,90 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00407") +public class BenchmarkTest00407 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00407"); + if (param == null) param = ""; + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00408.java b/OWASP DATASET/BenchmarkTest00408.java new file mode 100644 index 0000000000000000000000000000000000000000..d9e22d402f2914062068265eb4af2515bc73148a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00408.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00408") +public class BenchmarkTest00408 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00408"); + if (param == null) param = ""; + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00409.java b/OWASP DATASET/BenchmarkTest00409.java new file mode 100644 index 0000000000000000000000000000000000000000..801c9b380290ab11b43781c4b4554e23d9418d34 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00409.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00409") +public class BenchmarkTest00409 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00409"); + if (param == null) param = ""; + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00410.java b/OWASP DATASET/BenchmarkTest00410.java new file mode 100644 index 0000000000000000000000000000000000000000..38903345381391726e587bfbe738eaa8234958c5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00410.java @@ -0,0 +1,71 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00410") +public class BenchmarkTest00410 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00410"); + if (param == null) param = ""; + + String bar = "safe!"; + java.util.HashMap map77851 = new java.util.HashMap(); + map77851.put("keyA-77851", "a_Value"); // put some stuff in the collection + map77851.put("keyB-77851", param); // put it in a collection + map77851.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map77851.get("keyB-77851"); // get it back out + bar = (String) map77851.get("keyA-77851"); // get safe value back out + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00411.java b/OWASP DATASET/BenchmarkTest00411.java new file mode 100644 index 0000000000000000000000000000000000000000..7056c37a82528de955ee745dc72b19b32dcf5e70 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00411.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00411") +public class BenchmarkTest00411 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00411"); + if (param == null) param = ""; + + // Chain a bunch of propagators in sequence + String a18204 = param; // assign + StringBuilder b18204 = new StringBuilder(a18204); // stick in stringbuilder + b18204.append(" SafeStuff"); // append some safe content + b18204.replace( + b18204.length() - "Chars".length(), + b18204.length(), + "Chars"); // replace some of the end content + java.util.HashMap map18204 = new java.util.HashMap(); + map18204.put("key18204", b18204.toString()); // put in a collection + String c18204 = (String) map18204.get("key18204"); // get it back out + String d18204 = c18204.substring(0, c18204.length() - 1); // extract most of it + String e18204 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d18204.getBytes()))); // B64 encode and decode it + String f18204 = e18204.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g18204 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g18204); // reflection + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00412.java b/OWASP DATASET/BenchmarkTest00412.java new file mode 100644 index 0000000000000000000000000000000000000000..b0e9b14b27b65ba3730089d04a6b24c765d5d06c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00412.java @@ -0,0 +1,73 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00412") +public class BenchmarkTest00412 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00412"); + if (param == null) param = ""; + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + try { + Process p = r.exec(cmd, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00413.java b/OWASP DATASET/BenchmarkTest00413.java new file mode 100644 index 0000000000000000000000000000000000000000..1d05f9d6a8bcc8b71274f23225040c8abece37b1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00413.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00413") +public class BenchmarkTest00413 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00413"); + if (param == null) param = ""; + + String bar = "safe!"; + java.util.HashMap map27963 = new java.util.HashMap(); + map27963.put("keyA-27963", "a-Value"); // put some stuff in the collection + map27963.put("keyB-27963", param); // put it in a collection + map27963.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map27963.get("keyB-27963"); // get it back out + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00414.java b/OWASP DATASET/BenchmarkTest00414.java new file mode 100644 index 0000000000000000000000000000000000000000..feb500fa5af252bd03b2502611cadeb23389bee1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00414.java @@ -0,0 +1,133 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00414") +public class BenchmarkTest00414 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00414"); + if (param == null) param = ""; + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + getNextNumber(numGen, randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeBystander"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } + + void getNextNumber(java.util.Random generator, byte[] barray) { + generator.nextBytes(barray); + } +} diff --git a/OWASP DATASET/BenchmarkTest00415.java b/OWASP DATASET/BenchmarkTest00415.java new file mode 100644 index 0000000000000000000000000000000000000000..fd400566b8bd9e585ab7474d47ffec32c27c4f9e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00415.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00415") +public class BenchmarkTest00415 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00415"); + if (param == null) param = ""; + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00416.java b/OWASP DATASET/BenchmarkTest00416.java new file mode 100644 index 0000000000000000000000000000000000000000..aa84001c3940977ae03e6b814461d04ae4ac5b1e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00416.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00416") +public class BenchmarkTest00416 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00416"); + if (param == null) param = ""; + + String bar = "safe!"; + java.util.HashMap map22488 = new java.util.HashMap(); + map22488.put("keyA-22488", "a-Value"); // put some stuff in the collection + map22488.put("keyB-22488", param); // put it in a collection + map22488.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map22488.get("keyB-22488"); // get it back out + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00417.java b/OWASP DATASET/BenchmarkTest00417.java new file mode 100644 index 0000000000000000000000000000000000000000..be1171f23c78679994e75f804daa7866eb1129c5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00417.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00417") +public class BenchmarkTest00417 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00417"); + if (param == null) param = ""; + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00418.java b/OWASP DATASET/BenchmarkTest00418.java new file mode 100644 index 0000000000000000000000000000000000000000..0177ab48b32159f4013b0b1dcb5a3a5d3f494f57 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00418.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00418") +public class BenchmarkTest00418 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00418"); + if (param == null) param = ""; + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00419.java b/OWASP DATASET/BenchmarkTest00419.java new file mode 100644 index 0000000000000000000000000000000000000000..fcdc1a586c7dc49cdad925c2baf38376b4eafc3f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00419.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00419") +public class BenchmarkTest00419 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00419"); + if (param == null) param = ""; + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + try { + double stuff = java.security.SecureRandom.getInstance("SHA1PRNG").nextGaussian(); + String rememberMeKey = + Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "SafeGayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextGaussian() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextGaussian() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00420.java b/OWASP DATASET/BenchmarkTest00420.java new file mode 100644 index 0000000000000000000000000000000000000000..ee08fc6901ad04b0a17a434fe0ceb0279b382311 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00420.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00420") +public class BenchmarkTest00420 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00420"); + if (param == null) param = ""; + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + try { + double stuff = java.security.SecureRandom.getInstance("SHA1PRNG").nextGaussian(); + String rememberMeKey = + Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "SafeGayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextGaussian() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextGaussian() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00421.java b/OWASP DATASET/BenchmarkTest00421.java new file mode 100644 index 0000000000000000000000000000000000000000..2f05337f4c1decc47bbc26d50b67542a04ef7434 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00421.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00421") +public class BenchmarkTest00421 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00421"); + if (param == null) param = ""; + + String bar = param; + + try { + int randNumber = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "SafeInga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt(int) - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt(int) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00422.java b/OWASP DATASET/BenchmarkTest00422.java new file mode 100644 index 0000000000000000000000000000000000000000..b87a76e8b04f136d6415448dd3db3f4a4f247c5b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00422.java @@ -0,0 +1,107 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00422") +public class BenchmarkTest00422 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00422"); + if (param == null) param = ""; + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + try { + int r = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "SafeIngrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00423.java b/OWASP DATASET/BenchmarkTest00423.java new file mode 100644 index 0000000000000000000000000000000000000000..0c59ef651712dab6d873b68cb230b0dc81081a4c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00423.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00423") +public class BenchmarkTest00423 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00423"); + if (param == null) param = ""; + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + try { + int r = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "SafeIngrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00424.java b/OWASP DATASET/BenchmarkTest00424.java new file mode 100644 index 0000000000000000000000000000000000000000..ea27b1aa58dc5efec37ca6a77d02d9dd5b544f4e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00424.java @@ -0,0 +1,64 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00424") +public class BenchmarkTest00424 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00424"); + if (param == null) param = ""; + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00425.java b/OWASP DATASET/BenchmarkTest00425.java new file mode 100644 index 0000000000000000000000000000000000000000..0c18c6102510977d738455118d6b0da718dbef3d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00425.java @@ -0,0 +1,58 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00425") +public class BenchmarkTest00425 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00425"); + if (param == null) param = ""; + + StringBuilder sbxyz2192 = new StringBuilder(param); + String bar = sbxyz2192.append("_SafeStuff").toString(); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00426.java b/OWASP DATASET/BenchmarkTest00426.java new file mode 100644 index 0000000000000000000000000000000000000000..58c12146f9861ca394e1052bbd68cb5a4d49e34c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00426.java @@ -0,0 +1,62 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00426") +public class BenchmarkTest00426 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00426"); + if (param == null) param = ""; + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String^,java.lang.Object) + request.getSession().setAttribute(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: '10340' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00427.java b/OWASP DATASET/BenchmarkTest00427.java new file mode 100644 index 0000000000000000000000000000000000000000..e95c43e303c8ab04461b18e4591a667aef9652fc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00427.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00427") +public class BenchmarkTest00427 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00427"); + if (param == null) param = ""; + + // Chain a bunch of propagators in sequence + String a70670 = param; // assign + StringBuilder b70670 = new StringBuilder(a70670); // stick in stringbuilder + b70670.append(" SafeStuff"); // append some safe content + b70670.replace( + b70670.length() - "Chars".length(), + b70670.length(), + "Chars"); // replace some of the end content + java.util.HashMap map70670 = new java.util.HashMap(); + map70670.put("key70670", b70670.toString()); // put in a collection + String c70670 = (String) map70670.get("key70670"); // get it back out + String d70670 = c70670.substring(0, c70670.length() - 1); // extract most of it + String e70670 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d70670.getBytes()))); // B64 encode and decode it + String f70670 = e70670.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f70670); // reflection + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00428.java b/OWASP DATASET/BenchmarkTest00428.java new file mode 100644 index 0000000000000000000000000000000000000000..ee8e851de3c6190b23436592b1cd8f1f48de7fec --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00428.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00428") +public class BenchmarkTest00428 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00428"); + if (param == null) param = ""; + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = connection.prepareStatement(sql); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00429.java b/OWASP DATASET/BenchmarkTest00429.java new file mode 100644 index 0000000000000000000000000000000000000000..c502ca7fc8d3bce2126dd54705e7d238915e9106 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00429.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00429") +public class BenchmarkTest00429 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00429"); + if (param == null) param = ""; + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00430.java b/OWASP DATASET/BenchmarkTest00430.java new file mode 100644 index 0000000000000000000000000000000000000000..76a7ed5a7f233f03eff7b2628b37d5e54b873c37 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00430.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00430") +public class BenchmarkTest00430 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00430"); + if (param == null) param = ""; + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00431.java b/OWASP DATASET/BenchmarkTest00431.java new file mode 100644 index 0000000000000000000000000000000000000000..5980ebd7915670afb85546f7ec6b0a98d5a273f2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00431.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00431") +public class BenchmarkTest00431 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00431"); + if (param == null) param = ""; + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.query( + sql, + new org.springframework.jdbc.core.RowMapper() { + @Override + public String mapRow(java.sql.ResultSet rs, int rowNum) + throws java.sql.SQLException { + try { + return rs.getString("USERNAME"); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper + .hideSQLErrors) { + return "Error processing query."; + } else throw e; + } + } + }); + response.getWriter().println("Your results are: "); + + for (String s : results) { + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(s) + "
"); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00432.java b/OWASP DATASET/BenchmarkTest00432.java new file mode 100644 index 0000000000000000000000000000000000000000..10616e47296e8e1d3916ac50ec87c4b0e1672ab6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00432.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00432") +public class BenchmarkTest00432 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00432"); + if (param == null) param = ""; + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List> list = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForList(sql); + response.getWriter().println("Your results are:
"); + + // System.out.println("Your results are"); + + for (Object o : list) { + response.getWriter() + .println( + org.owasp.esapi.ESAPI.encoder().encodeForHTML(o.toString()) + + "
"); + // System.out.println(o.toString()); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00433.java b/OWASP DATASET/BenchmarkTest00433.java new file mode 100644 index 0000000000000000000000000000000000000000..d9f3d917ace5580c482504a72c02e7442ca00419 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00433.java @@ -0,0 +1,80 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00433") +public class BenchmarkTest00433 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00433"); + if (param == null) param = ""; + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List> list = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForList(sql); + response.getWriter().println("Your results are:
"); + + // System.out.println("Your results are"); + + for (Object o : list) { + response.getWriter() + .println( + org.owasp.esapi.ESAPI.encoder().encodeForHTML(o.toString()) + + "
"); + // System.out.println(o.toString()); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00434.java b/OWASP DATASET/BenchmarkTest00434.java new file mode 100644 index 0000000000000000000000000000000000000000..c13ef88bc32ff5f82e0aaa310ba2ba390f52192c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00434.java @@ -0,0 +1,66 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00434") +public class BenchmarkTest00434 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00434"); + if (param == null) param = ""; + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00435.java b/OWASP DATASET/BenchmarkTest00435.java new file mode 100644 index 0000000000000000000000000000000000000000..8426d4b26f9b3cbe29fb4b5e92df4826340945b5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00435.java @@ -0,0 +1,68 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00435") +public class BenchmarkTest00435 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00435"); + if (param == null) param = ""; + + String bar = "safe!"; + java.util.HashMap map86691 = new java.util.HashMap(); + map86691.put("keyA-86691", "a-Value"); // put some stuff in the collection + map86691.put("keyB-86691", param); // put it in a collection + map86691.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map86691.get("keyB-86691"); // get it back out + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.addBatch(sql); + int[] counts = statement.executeBatch(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(sql, counts, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00436.java b/OWASP DATASET/BenchmarkTest00436.java new file mode 100644 index 0000000000000000000000000000000000000000..96437dcf6200103bdfca719f062207af88d28a8d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00436.java @@ -0,0 +1,67 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00436") +public class BenchmarkTest00436 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00436"); + if (param == null) param = ""; + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00437.java b/OWASP DATASET/BenchmarkTest00437.java new file mode 100644 index 0000000000000000000000000000000000000000..f162be3075b57ac527975dc8afc134c98b2cab25 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00437.java @@ -0,0 +1,67 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00437") +public class BenchmarkTest00437 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00437"); + if (param == null) param = ""; + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00438.java b/OWASP DATASET/BenchmarkTest00438.java new file mode 100644 index 0000000000000000000000000000000000000000..e50b930ea8e34150983e2d7b4f81985af0427f05 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00438.java @@ -0,0 +1,67 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00438") +public class BenchmarkTest00438 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00438"); + if (param == null) param = ""; + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new String[] {"username", "password"}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00439.java b/OWASP DATASET/BenchmarkTest00439.java new file mode 100644 index 0000000000000000000000000000000000000000..2cd2a4966327a64c9023f7c3c916dbc33e2638ff --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00439.java @@ -0,0 +1,62 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00439") +public class BenchmarkTest00439 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00439"); + if (param == null) param = ""; + + String bar = param; + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + java.sql.ResultSet rs = statement.executeQuery(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00440.java b/OWASP DATASET/BenchmarkTest00440.java new file mode 100644 index 0000000000000000000000000000000000000000..cc06f332ecae5d4bd952a52c7fac448c64f43331 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00440.java @@ -0,0 +1,68 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00440") +public class BenchmarkTest00440 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00440"); + if (param == null) param = ""; + + String bar = "safe!"; + java.util.HashMap map67409 = new java.util.HashMap(); + map67409.put("keyA-67409", "a_Value"); // put some stuff in the collection + map67409.put("keyB-67409", param); // put it in a collection + map67409.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map67409.get("keyB-67409"); // get it back out + bar = (String) map67409.get("keyA-67409"); // get safe value back out + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00441.java b/OWASP DATASET/BenchmarkTest00441.java new file mode 100644 index 0000000000000000000000000000000000000000..630664e61eb39326d7b96a59db07785bf8a81821 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00441.java @@ -0,0 +1,64 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00441") +public class BenchmarkTest00441 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00441"); + if (param == null) param = ""; + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00442.java b/OWASP DATASET/BenchmarkTest00442.java new file mode 100644 index 0000000000000000000000000000000000000000..b68ab0d5eddbaebd71ad297954c55c9f597883e6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00442.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest00442") +public class BenchmarkTest00442 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest00442"); + if (param == null) param = ""; + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + String result = xp.evaluate(expression, xmlDocument); + + response.getWriter().println("Your query results are: " + result + "
"); + + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00443.java b/OWASP DATASET/BenchmarkTest00443.java new file mode 100644 index 0000000000000000000000000000000000000000..f5320276a436eff02218941f507aefd7ddce613b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00443.java @@ -0,0 +1,158 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00443") +public class BenchmarkTest00443 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00443"); + if (values != null) param = values[0]; + } + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00444.java b/OWASP DATASET/BenchmarkTest00444.java new file mode 100644 index 0000000000000000000000000000000000000000..4f752e8dc3c79ef7e198de0a4676a3dc5fdfcc2e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00444.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00444") +public class BenchmarkTest00444 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00444"); + if (values != null) param = values[0]; + } + + String bar = param; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = org.owasp.benchmark.helpers.Utils.getCipher(); + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00445.java b/OWASP DATASET/BenchmarkTest00445.java new file mode 100644 index 0000000000000000000000000000000000000000..a1e6a0691fc73f21427ce2b1884574cd1ff03b54 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00445.java @@ -0,0 +1,142 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00445") +public class BenchmarkTest00445 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00445"); + if (values != null) param = values[0]; + } + + // Chain a bunch of propagators in sequence + String a98384 = param; // assign + StringBuilder b98384 = new StringBuilder(a98384); // stick in stringbuilder + b98384.append(" SafeStuff"); // append some safe content + b98384.replace( + b98384.length() - "Chars".length(), + b98384.length(), + "Chars"); // replace some of the end content + java.util.HashMap map98384 = new java.util.HashMap(); + map98384.put("key98384", b98384.toString()); // put in a collection + String c98384 = (String) map98384.get("key98384"); // get it back out + String d98384 = c98384.substring(0, c98384.length() - 1); // extract most of it + String e98384 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d98384.getBytes()))); // B64 encode and decode it + String f98384 = e98384.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f98384); // reflection + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00446.java b/OWASP DATASET/BenchmarkTest00446.java new file mode 100644 index 0000000000000000000000000000000000000000..e95ac55586ace7163bc986b1484fa415efc2eec6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00446.java @@ -0,0 +1,127 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00446") +public class BenchmarkTest00446 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00446"); + if (values != null) param = values[0]; + } + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00447.java b/OWASP DATASET/BenchmarkTest00447.java new file mode 100644 index 0000000000000000000000000000000000000000..37b8636dd22f8d15f4b664ac943bcf3bb3144e01 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00447.java @@ -0,0 +1,133 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00447") +public class BenchmarkTest00447 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00447"); + if (values != null) param = values[0]; + } + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "AES/CCM/NoPadding", java.security.Security.getProvider("BC")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00448.java b/OWASP DATASET/BenchmarkTest00448.java new file mode 100644 index 0000000000000000000000000000000000000000..144b4e0f73f809faf8e2399a9e7a0252fd0fe71c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00448.java @@ -0,0 +1,118 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00448") +public class BenchmarkTest00448 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00448"); + if (values != null) param = values[0]; + } + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00449.java b/OWASP DATASET/BenchmarkTest00449.java new file mode 100644 index 0000000000000000000000000000000000000000..99ea57bc3e9f87cf8d49961c6da139a2395b611f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00449.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00449") +public class BenchmarkTest00449 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00449"); + if (values != null) param = values[0]; + } + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00450.java b/OWASP DATASET/BenchmarkTest00450.java new file mode 100644 index 0000000000000000000000000000000000000000..6fef7294181e5719df87f2982335b36cf394532a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00450.java @@ -0,0 +1,143 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00450") +public class BenchmarkTest00450 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00450"); + if (values != null) param = values[0]; + } + + // Chain a bunch of propagators in sequence + String a87006 = param; // assign + StringBuilder b87006 = new StringBuilder(a87006); // stick in stringbuilder + b87006.append(" SafeStuff"); // append some safe content + b87006.replace( + b87006.length() - "Chars".length(), + b87006.length(), + "Chars"); // replace some of the end content + java.util.HashMap map87006 = new java.util.HashMap(); + map87006.put("key87006", b87006.toString()); // put in a collection + String c87006 = (String) map87006.get("key87006"); // get it back out + String d87006 = c87006.substring(0, c87006.length() - 1); // extract most of it + String e87006 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d87006.getBytes()))); // B64 encode and decode it + String f87006 = e87006.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f87006); // reflection + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + // java.security.SecureRandom random = new java.security.SecureRandom(); + // byte[] iv = random.generateSeed(16); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg2", "AES/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00451.java b/OWASP DATASET/BenchmarkTest00451.java new file mode 100644 index 0000000000000000000000000000000000000000..1026fded179f6e16dd0de353c35a584c976fc5cc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00451.java @@ -0,0 +1,128 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00451") +public class BenchmarkTest00451 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00451"); + if (values != null) param = values[0]; + } + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + // java.security.SecureRandom random = new java.security.SecureRandom(); + // byte[] iv = random.generateSeed(16); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg2", "AES/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00452.java b/OWASP DATASET/BenchmarkTest00452.java new file mode 100644 index 0000000000000000000000000000000000000000..cb18fa574578ca385454987987c9d5350f372516 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00452.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00452") +public class BenchmarkTest00452 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00452"); + if (values != null) param = values[0]; + } + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00453.java b/OWASP DATASET/BenchmarkTest00453.java new file mode 100644 index 0000000000000000000000000000000000000000..91885f681d04cf6c9ceaa7d3c73fcc2f7ce188ed --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00453.java @@ -0,0 +1,98 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00453") +public class BenchmarkTest00453 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00453"); + if (values != null) param = values[0]; + } + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + // FILE URIs are tricky because they are different between Mac and Windows because of lack + // of standardization. + // Mac requires an extra slash for some reason. + String startURIslashes = ""; + if (System.getProperty("os.name").indexOf("Windows") != -1) + if (System.getProperty("os.name").indexOf("Windows") != -1) startURIslashes = "/"; + else startURIslashes = "//"; + + try { + java.net.URI fileURI = + new java.net.URI( + "file", + null, + startURIslashes + + org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + .replace('\\', java.io.File.separatorChar) + .replace(' ', '_') + + bar, + null, + null); + java.io.File fileTarget = new java.io.File(fileURI); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } catch (java.net.URISyntaxException e) { + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00454.java b/OWASP DATASET/BenchmarkTest00454.java new file mode 100644 index 0000000000000000000000000000000000000000..1fba508ac9b9e8425ea3759e395021d3d99dc00a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00454.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00454") +public class BenchmarkTest00454 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00454"); + if (values != null) param = values[0]; + } + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(new java.io.File(fileName)); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting FileInputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00455.java b/OWASP DATASET/BenchmarkTest00455.java new file mode 100644 index 0000000000000000000000000000000000000000..14283f765f4dca189661059304a06f9618c41bbe --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00455.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00455") +public class BenchmarkTest00455 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00455"); + if (values != null) param = values[0]; + } + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(fileName); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00456.java b/OWASP DATASET/BenchmarkTest00456.java new file mode 100644 index 0000000000000000000000000000000000000000..800dc8b1279904c9168e0b35dc2b35d90b0746b2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00456.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00456") +public class BenchmarkTest00456 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00456"); + if (values != null) param = values[0]; + } + + String bar = "safe!"; + java.util.HashMap map49381 = new java.util.HashMap(); + map49381.put("keyA-49381", "a-Value"); // put some stuff in the collection + map49381.put("keyB-49381", param); // put it in a collection + map49381.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map49381.get("keyB-49381"); // get it back out + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(fileName); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00457.java b/OWASP DATASET/BenchmarkTest00457.java new file mode 100644 index 0000000000000000000000000000000000000000..8fe5caf0060a9ea8b38cf996c7b5b392f009dc39 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00457.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00457") +public class BenchmarkTest00457 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00457"); + if (values != null) param = values[0]; + } + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName)); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00458.java b/OWASP DATASET/BenchmarkTest00458.java new file mode 100644 index 0000000000000000000000000000000000000000..c2213df458ba7b5327f646100edc55c2df7eb424 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00458.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00458") +public class BenchmarkTest00458 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00458"); + if (values != null) param = values[0]; + } + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName)); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00459.java b/OWASP DATASET/BenchmarkTest00459.java new file mode 100644 index 0000000000000000000000000000000000000000..980b47bed106aa7b54a35113655cdf357d697ef9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00459.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00459") +public class BenchmarkTest00459 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00459"); + if (values != null) param = values[0]; + } + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00460.java b/OWASP DATASET/BenchmarkTest00460.java new file mode 100644 index 0000000000000000000000000000000000000000..6fb50e40e33a042ba3025e6a869880b79980c80c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00460.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00460") +public class BenchmarkTest00460 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00460"); + if (values != null) param = values[0]; + } + + // Chain a bunch of propagators in sequence + String a62588 = param; // assign + StringBuilder b62588 = new StringBuilder(a62588); // stick in stringbuilder + b62588.append(" SafeStuff"); // append some safe content + b62588.replace( + b62588.length() - "Chars".length(), + b62588.length(), + "Chars"); // replace some of the end content + java.util.HashMap map62588 = new java.util.HashMap(); + map62588.put("key62588", b62588.toString()); // put in a collection + String c62588 = (String) map62588.get("key62588"); // get it back out + String d62588 = c62588.substring(0, c62588.length() - 1); // extract most of it + String e62588 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d62588.getBytes()))); // B64 encode and decode it + String f62588 = e62588.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g62588 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g62588); // reflection + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + java.io.InputStream is = null; + + try { + java.nio.file.Path path = java.nio.file.Paths.get(fileName); + is = java.nio.file.Files.newInputStream(path, java.nio.file.StandardOpenOption.READ); + byte[] b = new byte[1000]; + int size = is.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + is.close(); + } catch (Exception e) { + System.out.println("Couldn't open InputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting InputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (is != null) { + try { + is.close(); + is = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00461.java b/OWASP DATASET/BenchmarkTest00461.java new file mode 100644 index 0000000000000000000000000000000000000000..98bb1390aaf54fe9074dcf57780a231fbe2fe1d4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00461.java @@ -0,0 +1,101 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00461") +public class BenchmarkTest00461 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00461"); + if (values != null) param = values[0]; + } + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + double value = java.lang.Math.random(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Doug"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + response.getWriter().println("Weak Randomness Test java.lang.Math.random() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00462.java b/OWASP DATASET/BenchmarkTest00462.java new file mode 100644 index 0000000000000000000000000000000000000000..23e53ca1dcb57e3f713c6a9a9d33e6667a97caba --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00462.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00462") +public class BenchmarkTest00462 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00462"); + if (values != null) param = values[0]; + } + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("SHA1", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00463.java b/OWASP DATASET/BenchmarkTest00463.java new file mode 100644 index 0000000000000000000000000000000000000000..f74ba7c9365daf82217e638e8fecb5606c66122c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00463.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00463") +public class BenchmarkTest00463 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00463"); + if (values != null) param = values[0]; + } + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("sha-384", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("sha-384", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00464.java b/OWASP DATASET/BenchmarkTest00464.java new file mode 100644 index 0000000000000000000000000000000000000000..7e9d8e90e46cd21eed460c52d3781fea003c375b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00464.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00464") +public class BenchmarkTest00464 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00464"); + if (values != null) param = values[0]; + } + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00465.java b/OWASP DATASET/BenchmarkTest00465.java new file mode 100644 index 0000000000000000000000000000000000000000..e0fcd19d288e8cdb2cf1d92e22271bb77cd8219e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00465.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00465") +public class BenchmarkTest00465 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00465"); + if (values != null) param = values[0]; + } + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00466.java b/OWASP DATASET/BenchmarkTest00466.java new file mode 100644 index 0000000000000000000000000000000000000000..fed57333f376b05a1c3afd69b536e6149805fe76 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00466.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00466") +public class BenchmarkTest00466 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00466"); + if (values != null) param = values[0]; + } + + String bar = "safe!"; + java.util.HashMap map46344 = new java.util.HashMap(); + map46344.put("keyA-46344", "a-Value"); // put some stuff in the collection + map46344.put("keyB-46344", param); // put it in a collection + map46344.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map46344.get("keyB-46344"); // get it back out + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00467.java b/OWASP DATASET/BenchmarkTest00467.java new file mode 100644 index 0000000000000000000000000000000000000000..de85fdc2a96e5149b3972877235022e62e8a48d3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00467.java @@ -0,0 +1,61 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00467") +public class BenchmarkTest00467 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00467"); + if (values != null) param = values[0]; + } + + String bar = "safe!"; + java.util.HashMap map88136 = new java.util.HashMap(); + map88136.put("keyA-88136", "a-Value"); // put some stuff in the collection + map88136.put("keyB-88136", param); // put it in a collection + map88136.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map88136.get("keyB-88136"); // get it back out + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(java.util.Locale.US, bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00468.java b/OWASP DATASET/BenchmarkTest00468.java new file mode 100644 index 0000000000000000000000000000000000000000..299d881d0570250a2376883fd433540c180079b0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00468.java @@ -0,0 +1,62 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00468") +public class BenchmarkTest00468 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00468"); + if (values != null) param = values[0]; + } + + String bar = "safe!"; + java.util.HashMap map50379 = new java.util.HashMap(); + map50379.put("keyA-50379", "a_Value"); // put some stuff in the collection + map50379.put("keyB-50379", param); // put it in a collection + map50379.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map50379.get("keyB-50379"); // get it back out + bar = (String) map50379.get("keyA-50379"); // get safe value back out + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(java.util.Locale.US, bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00469.java b/OWASP DATASET/BenchmarkTest00469.java new file mode 100644 index 0000000000000000000000000000000000000000..66c152e0fc13a1f7a75c14364063e3293385d3b2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00469.java @@ -0,0 +1,61 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00469") +public class BenchmarkTest00469 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00469"); + if (values != null) param = values[0]; + } + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00470.java b/OWASP DATASET/BenchmarkTest00470.java new file mode 100644 index 0000000000000000000000000000000000000000..792a80ecf1bbd05eefca7ecf0ba997685a13e28e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00470.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00470") +public class BenchmarkTest00470 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00470"); + if (values != null) param = values[0]; + } + + // Chain a bunch of propagators in sequence + String a1504 = param; // assign + StringBuilder b1504 = new StringBuilder(a1504); // stick in stringbuilder + b1504.append(" SafeStuff"); // append some safe content + b1504.replace( + b1504.length() - "Chars".length(), + b1504.length(), + "Chars"); // replace some of the end content + java.util.HashMap map1504 = new java.util.HashMap(); + map1504.put("key1504", b1504.toString()); // put in a collection + String c1504 = (String) map1504.get("key1504"); // get it back out + String d1504 = c1504.substring(0, c1504.length() - 1); // extract most of it + String e1504 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d1504.getBytes()))); // B64 encode and decode it + String f1504 = e1504.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g1504 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g1504); // reflection + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00471.java b/OWASP DATASET/BenchmarkTest00471.java new file mode 100644 index 0000000000000000000000000000000000000000..bb14300a0d2186ac32bf1d738e80351e0c77799b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00471.java @@ -0,0 +1,56 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00471") +public class BenchmarkTest00471 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00471"); + if (values != null) param = values[0]; + } + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00472.java b/OWASP DATASET/BenchmarkTest00472.java new file mode 100644 index 0000000000000000000000000000000000000000..55a891d9ce5ef3b9771b8ac5a0faf2b63601d267 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00472.java @@ -0,0 +1,61 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00472") +public class BenchmarkTest00472 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00472"); + if (values != null) param = values[0]; + } + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {bar, "b"}; + response.getWriter().printf("Formatted like: %1$s and %2$s.", obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00473.java b/OWASP DATASET/BenchmarkTest00473.java new file mode 100644 index 0000000000000000000000000000000000000000..f4e657825d8a91081dfa4507901e6c07d9853baa --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00473.java @@ -0,0 +1,63 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00473") +public class BenchmarkTest00473 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00473"); + if (values != null) param = values[0]; + } + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00474.java b/OWASP DATASET/BenchmarkTest00474.java new file mode 100644 index 0000000000000000000000000000000000000000..9932e4e4bf6b8e6ec9c749c2c9f5ce5d3b87b379 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00474.java @@ -0,0 +1,55 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00474") +public class BenchmarkTest00474 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00474"); + if (values != null) param = values[0]; + } + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00475.java b/OWASP DATASET/BenchmarkTest00475.java new file mode 100644 index 0000000000000000000000000000000000000000..5a0095342f95d0d657e47251dd9c1699ac816989 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00475.java @@ -0,0 +1,60 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00475") +public class BenchmarkTest00475 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00475"); + if (values != null) param = values[0]; + } + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00476.java b/OWASP DATASET/BenchmarkTest00476.java new file mode 100644 index 0000000000000000000000000000000000000000..2ae14763d58c015839ba8943be85d8f7f17ef75c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00476.java @@ -0,0 +1,60 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00476") +public class BenchmarkTest00476 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00476"); + if (values != null) param = values[0]; + } + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00477.java b/OWASP DATASET/BenchmarkTest00477.java new file mode 100644 index 0000000000000000000000000000000000000000..43d6189bb96e1d9b0b90e6560d8ee79b1b9fc8df --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00477.java @@ -0,0 +1,56 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00477") +public class BenchmarkTest00477 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00477"); + if (values != null) param = values[0]; + } + + StringBuilder sbxyz54686 = new StringBuilder(param); + String bar = sbxyz54686.append("_SafeStuff").toString(); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00478.java b/OWASP DATASET/BenchmarkTest00478.java new file mode 100644 index 0000000000000000000000000000000000000000..cbb1e7801db2a7d5fcc111b48506f7ea8e20bfd1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00478.java @@ -0,0 +1,62 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00478") +public class BenchmarkTest00478 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00478"); + if (values != null) param = values[0]; + } + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar.toCharArray()); + } +} diff --git a/OWASP DATASET/BenchmarkTest00479.java b/OWASP DATASET/BenchmarkTest00479.java new file mode 100644 index 0000000000000000000000000000000000000000..119fa0eb4ec36e46bebf8a10ff73b61fe0037737 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00479.java @@ -0,0 +1,59 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00479") +public class BenchmarkTest00479 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00479"); + if (values != null) param = values[0]; + } + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar.toCharArray(), 0, length); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00480.java b/OWASP DATASET/BenchmarkTest00480.java new file mode 100644 index 0000000000000000000000000000000000000000..2cc9fd10dff37465210e1325e015dde388de7e25 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00480.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00480") +public class BenchmarkTest00480 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00480"); + if (values != null) param = values[0]; + } + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(); + + pb.command(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00481.java b/OWASP DATASET/BenchmarkTest00481.java new file mode 100644 index 0000000000000000000000000000000000000000..03277a1bd2d81ad89ac618d655283d07c2177260 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00481.java @@ -0,0 +1,80 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00481") +public class BenchmarkTest00481 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00481"); + if (values != null) param = values[0]; + } + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00482.java b/OWASP DATASET/BenchmarkTest00482.java new file mode 100644 index 0000000000000000000000000000000000000000..bd3979354b3a59849cf941ee68253a11125c143d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00482.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00482") +public class BenchmarkTest00482 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00482"); + if (values != null) param = values[0]; + } + + String bar = param; + + byte[] bytes = new byte[10]; + new java.util.Random().nextBytes(bytes); + String rememberMeKey = org.owasp.esapi.ESAPI.encoder().encodeForBase64(bytes, true); + + String user = "Byron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextBytes() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00483.java b/OWASP DATASET/BenchmarkTest00483.java new file mode 100644 index 0000000000000000000000000000000000000000..6e2726d93b8f3e9ff1fb786a43eb68359f240d84 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00483.java @@ -0,0 +1,107 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00483") +public class BenchmarkTest00483 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00483"); + if (values != null) param = values[0]; + } + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + byte[] bytes = new byte[10]; + new java.util.Random().nextBytes(bytes); + String rememberMeKey = org.owasp.esapi.ESAPI.encoder().encodeForBase64(bytes, true); + + String user = "Byron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextBytes() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00484.java b/OWASP DATASET/BenchmarkTest00484.java new file mode 100644 index 0000000000000000000000000000000000000000..278e688416ddf93c7aa7c0459c64c8186affff0d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00484.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00484") +public class BenchmarkTest00484 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00484"); + if (values != null) param = values[0]; + } + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + double value = new java.util.Random().nextDouble(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Donna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextDouble() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00485.java b/OWASP DATASET/BenchmarkTest00485.java new file mode 100644 index 0000000000000000000000000000000000000000..80ea4ede8e3613b3eae524be660a1784603cfb3d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00485.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00485") +public class BenchmarkTest00485 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00485"); + if (values != null) param = values[0]; + } + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + int randNumber = new java.util.Random().nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "Inga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt(int) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00486.java b/OWASP DATASET/BenchmarkTest00486.java new file mode 100644 index 0000000000000000000000000000000000000000..18623b68c8196786da4a5ddfc61ba66251728dbf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00486.java @@ -0,0 +1,100 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00486") +public class BenchmarkTest00486 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00486"); + if (values != null) param = values[0]; + } + + String bar = param; + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00487.java b/OWASP DATASET/BenchmarkTest00487.java new file mode 100644 index 0000000000000000000000000000000000000000..5c6cf0b277322981d6d422145bb184aa83f38d77 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00487.java @@ -0,0 +1,105 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00487") +public class BenchmarkTest00487 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00487"); + if (values != null) param = values[0]; + } + + String bar = "safe!"; + java.util.HashMap map10732 = new java.util.HashMap(); + map10732.put("keyA-10732", "a-Value"); // put some stuff in the collection + map10732.put("keyB-10732", param); // put it in a collection + map10732.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map10732.get("keyB-10732"); // get it back out + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00488.java b/OWASP DATASET/BenchmarkTest00488.java new file mode 100644 index 0000000000000000000000000000000000000000..44e4755c7aca9f458ef06b2b541977ba09da2b6f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00488.java @@ -0,0 +1,111 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00488") +public class BenchmarkTest00488 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00488"); + if (values != null) param = values[0]; + } + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00489.java b/OWASP DATASET/BenchmarkTest00489.java new file mode 100644 index 0000000000000000000000000000000000000000..97882bfd302cadd04ba7452556efea2d6f68d82c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00489.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00489") +public class BenchmarkTest00489 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00489"); + if (values != null) param = values[0]; + } + + String bar = "safe!"; + java.util.HashMap map25864 = new java.util.HashMap(); + map25864.put("keyA-25864", "a-Value"); // put some stuff in the collection + map25864.put("keyB-25864", param); // put it in a collection + map25864.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map25864.get("keyB-25864"); // get it back out + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00490.java b/OWASP DATASET/BenchmarkTest00490.java new file mode 100644 index 0000000000000000000000000000000000000000..dec673c7eb04aad6d91c83a8208406965ba9b72a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00490.java @@ -0,0 +1,111 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00490") +public class BenchmarkTest00490 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00490"); + if (values != null) param = values[0]; + } + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00491.java b/OWASP DATASET/BenchmarkTest00491.java new file mode 100644 index 0000000000000000000000000000000000000000..6aed9f3b0e8fe3b753252a98aa016e559789e591 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00491.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest00491") +public class BenchmarkTest00491 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00491"); + if (values != null) param = values[0]; + } + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz92030 = new StringBuilder(param); + bar = sbxyz92030.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00492.java b/OWASP DATASET/BenchmarkTest00492.java new file mode 100644 index 0000000000000000000000000000000000000000..52ed0a662a64ca102629b655b4f0ff5c2b8e857f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00492.java @@ -0,0 +1,57 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00492") +public class BenchmarkTest00492 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00492"); + if (values != null) param = values[0]; + } + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write("Parameter value: " + bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00493.java b/OWASP DATASET/BenchmarkTest00493.java new file mode 100644 index 0000000000000000000000000000000000000000..cb82b58df2d4fbd381f69a7bd7f33d6442a8563b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00493.java @@ -0,0 +1,61 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00493") +public class BenchmarkTest00493 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00493"); + if (values != null) param = values[0]; + } + + String bar = "safe!"; + java.util.HashMap map8943 = new java.util.HashMap(); + map8943.put("keyA-8943", "a_Value"); // put some stuff in the collection + map8943.put("keyB-8943", param); // put it in a collection + map8943.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map8943.get("keyB-8943"); // get it back out + bar = (String) map8943.get("keyA-8943"); // get safe value back out + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write("Parameter value: " + bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00494.java b/OWASP DATASET/BenchmarkTest00494.java new file mode 100644 index 0000000000000000000000000000000000000000..453857182407caf1049925d98f8228efa8de35ef --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00494.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00494") +public class BenchmarkTest00494 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00494"); + if (values != null) param = values[0]; + } + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ping -c1 "); + args = new String[] {a1, a2, cmd + bar}; + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00495.java b/OWASP DATASET/BenchmarkTest00495.java new file mode 100644 index 0000000000000000000000000000000000000000..9c03a1bf3cd8a396007c7c28a25bfa967d1e47ba --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00495.java @@ -0,0 +1,80 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00495") +public class BenchmarkTest00495 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00495"); + if (values != null) param = values[0]; + } + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00496.java b/OWASP DATASET/BenchmarkTest00496.java new file mode 100644 index 0000000000000000000000000000000000000000..0227346cb1744337c754173c953bdc8cbe4dda21 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00496.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00496") +public class BenchmarkTest00496 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00496"); + if (values != null) param = values[0]; + } + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00497.java b/OWASP DATASET/BenchmarkTest00497.java new file mode 100644 index 0000000000000000000000000000000000000000..10dabf6245e0df687cf96f73a3d68b299e2b6ffc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00497.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00497") +public class BenchmarkTest00497 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00497"); + if (values != null) param = values[0]; + } + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00498.java b/OWASP DATASET/BenchmarkTest00498.java new file mode 100644 index 0000000000000000000000000000000000000000..ed23b927eda9af6a3d71551e50eae916ff823eb4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00498.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00498") +public class BenchmarkTest00498 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00498"); + if (values != null) param = values[0]; + } + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00499.java b/OWASP DATASET/BenchmarkTest00499.java new file mode 100644 index 0000000000000000000000000000000000000000..51a1433178ff3f244ff23b0593c54b2da37969b3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00499.java @@ -0,0 +1,71 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00499") +public class BenchmarkTest00499 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00499"); + if (values != null) param = values[0]; + } + + String bar = param; + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00500.java b/OWASP DATASET/BenchmarkTest00500.java new file mode 100644 index 0000000000000000000000000000000000000000..a4680882cfa56e58b04a2bf785867269b5539417 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00500.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00500") +public class BenchmarkTest00500 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00500"); + if (values != null) param = values[0]; + } + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = + r.exec(cmd + bar, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00501.java b/OWASP DATASET/BenchmarkTest00501.java new file mode 100644 index 0000000000000000000000000000000000000000..0a9fa86e2252769c93012d525bcd2b73b9d6d031 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00501.java @@ -0,0 +1,125 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00501") +public class BenchmarkTest00501 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00501"); + if (values != null) param = values[0]; + } + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00502.java b/OWASP DATASET/BenchmarkTest00502.java new file mode 100644 index 0000000000000000000000000000000000000000..dc631cbd71a924deede2b79b74658501a3361e41 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00502.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00502") +public class BenchmarkTest00502 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00502"); + if (values != null) param = values[0]; + } + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + getNextNumber(numGen, randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeBystander"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } + + void getNextNumber(java.util.Random generator, byte[] barray) { + generator.nextBytes(barray); + } +} diff --git a/OWASP DATASET/BenchmarkTest00503.java b/OWASP DATASET/BenchmarkTest00503.java new file mode 100644 index 0000000000000000000000000000000000000000..9a9404f2993060c14c9cf201a3f17026f2ca3d09 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00503.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00503") +public class BenchmarkTest00503 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00503"); + if (values != null) param = values[0]; + } + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00504.java b/OWASP DATASET/BenchmarkTest00504.java new file mode 100644 index 0000000000000000000000000000000000000000..1d1cf926c9f9effd637f2d0bfae8e9d17595ecf5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00504.java @@ -0,0 +1,107 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00504") +public class BenchmarkTest00504 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00504"); + if (values != null) param = values[0]; + } + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + try { + float rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextFloat(); + String rememberMeKey = + Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeFloyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextFloat() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextFloat() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00505.java b/OWASP DATASET/BenchmarkTest00505.java new file mode 100644 index 0000000000000000000000000000000000000000..0bf369bb8e5ba24512ad74321c67487f714a925a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00505.java @@ -0,0 +1,111 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00505") +public class BenchmarkTest00505 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00505"); + if (values != null) param = values[0]; + } + + String bar = "safe!"; + java.util.HashMap map67557 = new java.util.HashMap(); + map67557.put("keyA-67557", "a-Value"); // put some stuff in the collection + map67557.put("keyB-67557", param); // put it in a collection + map67557.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map67557.get("keyB-67557"); // get it back out + + try { + int randNumber = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "SafeInga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt(int) - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt(int) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00506.java b/OWASP DATASET/BenchmarkTest00506.java new file mode 100644 index 0000000000000000000000000000000000000000..023e17a3e5ef426b542d31775d9fc2d6df3d37a1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00506.java @@ -0,0 +1,127 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00506") +public class BenchmarkTest00506 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00506"); + if (values != null) param = values[0]; + } + + // Chain a bunch of propagators in sequence + String a5528 = param; // assign + StringBuilder b5528 = new StringBuilder(a5528); // stick in stringbuilder + b5528.append(" SafeStuff"); // append some safe content + b5528.replace( + b5528.length() - "Chars".length(), + b5528.length(), + "Chars"); // replace some of the end content + java.util.HashMap map5528 = new java.util.HashMap(); + map5528.put("key5528", b5528.toString()); // put in a collection + String c5528 = (String) map5528.get("key5528"); // get it back out + String d5528 = c5528.substring(0, c5528.length() - 1); // extract most of it + String e5528 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d5528.getBytes()))); // B64 encode and decode it + String f5528 = e5528.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g5528 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g5528); // reflection + + try { + int r = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "SafeIngrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00507.java b/OWASP DATASET/BenchmarkTest00507.java new file mode 100644 index 0000000000000000000000000000000000000000..3cbb17cc111864071c01997165a4bd4a2f9b9a66 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00507.java @@ -0,0 +1,107 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00507") +public class BenchmarkTest00507 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00507"); + if (values != null) param = values[0]; + } + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + try { + int r = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "SafeIngrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00508.java b/OWASP DATASET/BenchmarkTest00508.java new file mode 100644 index 0000000000000000000000000000000000000000..2be02f7bc8d98b42ba5f30a649387836ce89e449 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00508.java @@ -0,0 +1,62 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00508") +public class BenchmarkTest00508 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00508"); + if (values != null) param = values[0]; + } + + StringBuilder sbxyz10446 = new StringBuilder(param); + String bar = sbxyz10446.append("_SafeStuff").toString(); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00509.java b/OWASP DATASET/BenchmarkTest00509.java new file mode 100644 index 0000000000000000000000000000000000000000..4e452ae0f72dd678de9fb180fa73f1d30fce49ae --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00509.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00509") +public class BenchmarkTest00509 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00509"); + if (values != null) param = values[0]; + } + + String bar = "safe!"; + java.util.HashMap map94841 = new java.util.HashMap(); + map94841.put("keyA-94841", "a_Value"); // put some stuff in the collection + map94841.put("keyB-94841", param); // put it in a collection + map94841.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map94841.get("keyB-94841"); // get it back out + bar = (String) map94841.get("keyA-94841"); // get safe value back out + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00510.java b/OWASP DATASET/BenchmarkTest00510.java new file mode 100644 index 0000000000000000000000000000000000000000..7267eabd86479e44498a2186190dab810edfd428 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00510.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-00/BenchmarkTest00510") +public class BenchmarkTest00510 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00510"); + if (values != null) param = values[0]; + } + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00511.java b/OWASP DATASET/BenchmarkTest00511.java new file mode 100644 index 0000000000000000000000000000000000000000..bbb216be6da43130ceb490581120ae0ead7d626e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00511.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00511") +public class BenchmarkTest00511 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00511"); + if (values != null) param = values[0]; + } + + String bar = "safe!"; + java.util.HashMap map94915 = new java.util.HashMap(); + map94915.put("keyA-94915", "a_Value"); // put some stuff in the collection + map94915.put("keyB-94915", param); // put it in a collection + map94915.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map94915.get("keyB-94915"); // get it back out + bar = (String) map94915.get("keyA-94915"); // get safe value back out + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00512.java b/OWASP DATASET/BenchmarkTest00512.java new file mode 100644 index 0000000000000000000000000000000000000000..60b0cb34dd0b11f03e6bc99dbac1c2b52060e1d8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00512.java @@ -0,0 +1,66 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00512") +public class BenchmarkTest00512 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00512"); + if (values != null) param = values[0]; + } + + String bar = param; + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00513.java b/OWASP DATASET/BenchmarkTest00513.java new file mode 100644 index 0000000000000000000000000000000000000000..75bcc001594d07e92eb96a0a102b8c40f99875a0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00513.java @@ -0,0 +1,72 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00513") +public class BenchmarkTest00513 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00513"); + if (values != null) param = values[0]; + } + + String bar = "safe!"; + java.util.HashMap map63945 = new java.util.HashMap(); + map63945.put("keyA-63945", "a_Value"); // put some stuff in the collection + map63945.put("keyB-63945", param); // put it in a collection + map63945.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map63945.get("keyB-63945"); // get it back out + bar = (String) map63945.get("keyA-63945"); // get safe value back out + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00514.java b/OWASP DATASET/BenchmarkTest00514.java new file mode 100644 index 0000000000000000000000000000000000000000..773c7280d5d958737237ad4077b0d22691a7ea48 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00514.java @@ -0,0 +1,71 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00514") +public class BenchmarkTest00514 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00514"); + if (values != null) param = values[0]; + } + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00515.java b/OWASP DATASET/BenchmarkTest00515.java new file mode 100644 index 0000000000000000000000000000000000000000..72806247f37b81784964ad5a8f6c722f4bc9d7f2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00515.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00515") +public class BenchmarkTest00515 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00515"); + if (values != null) param = values[0]; + } + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00516.java b/OWASP DATASET/BenchmarkTest00516.java new file mode 100644 index 0000000000000000000000000000000000000000..f9091b05acc8775e790d2b6bb751515278bf99f4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00516.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00516") +public class BenchmarkTest00516 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00516"); + if (values != null) param = values[0]; + } + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00517.java b/OWASP DATASET/BenchmarkTest00517.java new file mode 100644 index 0000000000000000000000000000000000000000..192af9e3a391e8b6188883fb8e96b6a7aafcc1a8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00517.java @@ -0,0 +1,71 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00517") +public class BenchmarkTest00517 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00517"); + if (values != null) param = values[0]; + } + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new String[] {"username", "password"}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00518.java b/OWASP DATASET/BenchmarkTest00518.java new file mode 100644 index 0000000000000000000000000000000000000000..da6da56bd6519a3e47d25ea0b87baa211a1fd403 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00518.java @@ -0,0 +1,68 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00518") +public class BenchmarkTest00518 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00518"); + if (values != null) param = values[0]; + } + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00519.java b/OWASP DATASET/BenchmarkTest00519.java new file mode 100644 index 0000000000000000000000000000000000000000..1f3cd3dd5917880cddf13d8a3b8b5fa784d781f3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00519.java @@ -0,0 +1,72 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00519") +public class BenchmarkTest00519 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00519"); + if (values != null) param = values[0]; + } + + String bar = "safe!"; + java.util.HashMap map30190 = new java.util.HashMap(); + map30190.put("keyA-30190", "a_Value"); // put some stuff in the collection + map30190.put("keyB-30190", param); // put it in a collection + map30190.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map30190.get("keyB-30190"); // get it back out + bar = (String) map30190.get("keyA-30190"); // get safe value back out + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new String[] {"USERNAME", "PASSWORD"}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00520.java b/OWASP DATASET/BenchmarkTest00520.java new file mode 100644 index 0000000000000000000000000000000000000000..1687e5245a6daba7d9335d432d8c168a42cb44e4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00520.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest00520") +public class BenchmarkTest00520 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest00520"); + if (values != null) param = values[0]; + } + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + String result = xp.evaluate(expression, xmlDocument); + + response.getWriter().println("Your query results are: " + result + "
"); + + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00521.java b/OWASP DATASET/BenchmarkTest00521.java new file mode 100644 index 0000000000000000000000000000000000000000..42b9e4ff3fcb4715290abff4d782b4415c59771d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00521.java @@ -0,0 +1,167 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00521") +public class BenchmarkTest00521 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00521")) { + param = name; + flag = false; + } + } + } + } + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "DES/CBC/PKCS5PADDING", java.security.Security.getProvider("SunJCE")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00522.java b/OWASP DATASET/BenchmarkTest00522.java new file mode 100644 index 0000000000000000000000000000000000000000..d059b9b400c23c8df908d74298525d4534e3ba6a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00522.java @@ -0,0 +1,171 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00522") +public class BenchmarkTest00522 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00522")) { + param = name; + flag = false; + } + } + } + } + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00523.java b/OWASP DATASET/BenchmarkTest00523.java new file mode 100644 index 0000000000000000000000000000000000000000..310c1ba46f399f4bd7133b7b3ea9e223ee476169 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00523.java @@ -0,0 +1,143 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00523") +public class BenchmarkTest00523 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00523")) { + param = name; + flag = false; + } + } + } + } + + // Chain a bunch of propagators in sequence + String a87760 = param; // assign + StringBuilder b87760 = new StringBuilder(a87760); // stick in stringbuilder + b87760.append(" SafeStuff"); // append some safe content + b87760.replace( + b87760.length() - "Chars".length(), + b87760.length(), + "Chars"); // replace some of the end content + java.util.HashMap map87760 = new java.util.HashMap(); + map87760.put("key87760", b87760.toString()); // put in a collection + String c87760 = (String) map87760.get("key87760"); // get it back out + String d87760 = c87760.substring(0, c87760.length() - 1); // extract most of it + String e87760 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d87760.getBytes()))); // B64 encode and decode it + String f87760 = e87760.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g87760 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g87760); // reflection + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = org.owasp.benchmark.helpers.Utils.getCipher(); + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00524.java b/OWASP DATASET/BenchmarkTest00524.java new file mode 100644 index 0000000000000000000000000000000000000000..3bd22d60f5b6054ffdd59b52a8c43fd0533f127e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00524.java @@ -0,0 +1,153 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00524") +public class BenchmarkTest00524 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00524")) { + param = name; + flag = false; + } + } + } + } + + // Chain a bunch of propagators in sequence + String a18964 = param; // assign + StringBuilder b18964 = new StringBuilder(a18964); // stick in stringbuilder + b18964.append(" SafeStuff"); // append some safe content + b18964.replace( + b18964.length() - "Chars".length(), + b18964.length(), + "Chars"); // replace some of the end content + java.util.HashMap map18964 = new java.util.HashMap(); + map18964.put("key18964", b18964.toString()); // put in a collection + String c18964 = (String) map18964.get("key18964"); // get it back out + String d18964 = c18964.substring(0, c18964.length() - 1); // extract most of it + String e18964 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d18964.getBytes()))); // B64 encode and decode it + String f18964 = e18964.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f18964); // reflection + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + // java.security.SecureRandom random = new java.security.SecureRandom(); + // byte[] iv = random.generateSeed(16); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg2", "AES/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00525.java b/OWASP DATASET/BenchmarkTest00525.java new file mode 100644 index 0000000000000000000000000000000000000000..2a672370ab127a2d5cd4afbeae5b00830da90662 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00525.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00525") +public class BenchmarkTest00525 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00525")) { + param = name; + flag = false; + } + } + } + } + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + java.io.File fileTarget = + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR, bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00526.java b/OWASP DATASET/BenchmarkTest00526.java new file mode 100644 index 0000000000000000000000000000000000000000..2870f0f235004d0359411ba08089d4468a27b1de --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00526.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00526") +public class BenchmarkTest00526 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00526")) { + param = name; + flag = false; + } + } + } + } + + String bar = param; + + java.io.File fileTarget = new java.io.File(bar, "/Test.txt"); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00527.java b/OWASP DATASET/BenchmarkTest00527.java new file mode 100644 index 0000000000000000000000000000000000000000..1a18a4b73e123d79afc97ab7c8e5f603266f6e22 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00527.java @@ -0,0 +1,80 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00527") +public class BenchmarkTest00527 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00527")) { + param = name; + flag = false; + } + } + } + } + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + java.io.File fileTarget = new java.io.File(bar, "/Test.txt"); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00528.java b/OWASP DATASET/BenchmarkTest00528.java new file mode 100644 index 0000000000000000000000000000000000000000..9104f14854a78d56f7e01047c85bfa95d7ec1585 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00528.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00528") +public class BenchmarkTest00528 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00528")) { + param = name; + flag = false; + } + } + } + } + + String bar = "safe!"; + java.util.HashMap map6751 = new java.util.HashMap(); + map6751.put("keyA-6751", "a-Value"); // put some stuff in the collection + map6751.put("keyB-6751", param); // put it in a collection + map6751.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map6751.get("keyB-6751"); // get it back out + + // FILE URIs are tricky because they are different between Mac and Windows because of lack + // of standardization. + // Mac requires an extra slash for some reason. + String startURIslashes = ""; + if (System.getProperty("os.name").indexOf("Windows") != -1) + if (System.getProperty("os.name").indexOf("Windows") != -1) startURIslashes = "/"; + else startURIslashes = "//"; + + try { + java.net.URI fileURI = + new java.net.URI( + "file", + null, + startURIslashes + + org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + .replace('\\', java.io.File.separatorChar) + .replace(' ', '_') + + bar, + null, + null); + java.io.File fileTarget = new java.io.File(fileURI); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } catch (java.net.URISyntaxException e) { + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00529.java b/OWASP DATASET/BenchmarkTest00529.java new file mode 100644 index 0000000000000000000000000000000000000000..d2e2f6af2a2b5378f0749457afef5ce672d07d42 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00529.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00529") +public class BenchmarkTest00529 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00529")) { + param = name; + flag = false; + } + } + } + } + + String bar = param; + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(fileName); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00530.java b/OWASP DATASET/BenchmarkTest00530.java new file mode 100644 index 0000000000000000000000000000000000000000..88b7a2f88bcacb1aaf7e4436c8fc88af07adfd6b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00530.java @@ -0,0 +1,133 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest00530") +public class BenchmarkTest00530 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00530")) { + param = name; + flag = false; + } + } + } + } + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person)(uid=" + bar + "))"; + + javax.naming.directory.DirContext ctx = ads.getDirContext(); + javax.naming.directory.InitialDirContext idc = + (javax.naming.directory.InitialDirContext) ctx; + boolean found = false; + javax.naming.NamingEnumeration results = + idc.search(base, filter, sc); + + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00531.java b/OWASP DATASET/BenchmarkTest00531.java new file mode 100644 index 0000000000000000000000000000000000000000..6fda87af7ac1d5a9911c25c3eaf3871b6c7ae60f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00531.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00531") +public class BenchmarkTest00531 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00531")) { + param = name; + flag = false; + } + } + } + } + + String bar = "safe!"; + java.util.HashMap map38098 = new java.util.HashMap(); + map38098.put("keyA-38098", "a-Value"); // put some stuff in the collection + map38098.put("keyB-38098", param); // put it in a collection + map38098.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map38098.get("keyB-38098"); // get it back out + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("SHA1", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00532.java b/OWASP DATASET/BenchmarkTest00532.java new file mode 100644 index 0000000000000000000000000000000000000000..0dd2ef43dfdc4bad40c8e5424c7996fcddc513b7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00532.java @@ -0,0 +1,136 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00532") +public class BenchmarkTest00532 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00532")) { + param = name; + flag = false; + } + } + } + } + + // Chain a bunch of propagators in sequence + String a25409 = param; // assign + StringBuilder b25409 = new StringBuilder(a25409); // stick in stringbuilder + b25409.append(" SafeStuff"); // append some safe content + b25409.replace( + b25409.length() - "Chars".length(), + b25409.length(), + "Chars"); // replace some of the end content + java.util.HashMap map25409 = new java.util.HashMap(); + map25409.put("key25409", b25409.toString()); // put in a collection + String c25409 = (String) map25409.get("key25409"); // get it back out + String d25409 = c25409.substring(0, c25409.length() - 1); // extract most of it + String e25409 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d25409.getBytes()))); // B64 encode and decode it + String f25409 = e25409.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f25409); // reflection + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00533.java b/OWASP DATASET/BenchmarkTest00533.java new file mode 100644 index 0000000000000000000000000000000000000000..8daec3b0c855ffb3fe2a25d7b37dc54165425b03 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00533.java @@ -0,0 +1,126 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00533") +public class BenchmarkTest00533 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00533")) { + param = name; + flag = false; + } + } + } + } + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00534.java b/OWASP DATASET/BenchmarkTest00534.java new file mode 100644 index 0000000000000000000000000000000000000000..5ead2a84535b34a252852f21723a7ab0a83c002a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00534.java @@ -0,0 +1,135 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00534") +public class BenchmarkTest00534 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00534")) { + param = name; + flag = false; + } + } + } + } + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00535.java b/OWASP DATASET/BenchmarkTest00535.java new file mode 100644 index 0000000000000000000000000000000000000000..796bce7e7998f47078cade6ce95ec186ce69d06f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00535.java @@ -0,0 +1,122 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00535") +public class BenchmarkTest00535 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00535")) { + param = name; + flag = false; + } + } + } + } + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + try { + java.security.MessageDigest md = + java.security.MessageDigest.getInstance("SHA-512", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00536.java b/OWASP DATASET/BenchmarkTest00536.java new file mode 100644 index 0000000000000000000000000000000000000000..05861e826d07ba2645383455d21cc3f0ffad2968 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00536.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00536") +public class BenchmarkTest00536 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00536")) { + param = name; + flag = false; + } + } + } + } + + String bar = "safe!"; + java.util.HashMap map28714 = new java.util.HashMap(); + map28714.put("keyA-28714", "a-Value"); // put some stuff in the collection + map28714.put("keyB-28714", param); // put it in a collection + map28714.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map28714.get("keyB-28714"); // get it back out + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00537.java b/OWASP DATASET/BenchmarkTest00537.java new file mode 100644 index 0000000000000000000000000000000000000000..9cc2078b0560b68af3bbf3600570f72d5634f6a5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00537.java @@ -0,0 +1,111 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00537") +public class BenchmarkTest00537 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00537")) { + param = name; + flag = false; + } + } + } + } + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00538.java b/OWASP DATASET/BenchmarkTest00538.java new file mode 100644 index 0000000000000000000000000000000000000000..32a0d79d5a7634876e227fa67636bbe3bbce2913 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00538.java @@ -0,0 +1,131 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00538") +public class BenchmarkTest00538 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00538")) { + param = name; + flag = false; + } + } + } + } + + // Chain a bunch of propagators in sequence + String a75053 = param; // assign + StringBuilder b75053 = new StringBuilder(a75053); // stick in stringbuilder + b75053.append(" SafeStuff"); // append some safe content + b75053.replace( + b75053.length() - "Chars".length(), + b75053.length(), + "Chars"); // replace some of the end content + java.util.HashMap map75053 = new java.util.HashMap(); + map75053.put("key75053", b75053.toString()); // put in a collection + String c75053 = (String) map75053.get("key75053"); // get it back out + String d75053 = c75053.substring(0, c75053.length() - 1); // extract most of it + String e75053 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d75053.getBytes()))); // B64 encode and decode it + String f75053 = e75053.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f75053); // reflection + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-256"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00539.java b/OWASP DATASET/BenchmarkTest00539.java new file mode 100644 index 0000000000000000000000000000000000000000..aca7f7ccb71ea60700351af3bd53b45f060d2402 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00539.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00539") +public class BenchmarkTest00539 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00539")) { + param = name; + flag = false; + } + } + } + } + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-256"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00540.java b/OWASP DATASET/BenchmarkTest00540.java new file mode 100644 index 0000000000000000000000000000000000000000..9941769ac7d742c8c4c21956626613d9f70c89f6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00540.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00540") +public class BenchmarkTest00540 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00540")) { + param = name; + flag = false; + } + } + } + } + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00541.java b/OWASP DATASET/BenchmarkTest00541.java new file mode 100644 index 0000000000000000000000000000000000000000..bb8b5dd16eb970ea9d2d4fc8c9a5751ec0f2c076 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00541.java @@ -0,0 +1,73 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00541") +public class BenchmarkTest00541 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00541")) { + param = name; + flag = false; + } + } + } + } + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(java.util.Locale.US, bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00542.java b/OWASP DATASET/BenchmarkTest00542.java new file mode 100644 index 0000000000000000000000000000000000000000..62fbcf4a0c03a2dd4259730b5989b478ba733ea2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00542.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00542") +public class BenchmarkTest00542 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00542")) { + param = name; + flag = false; + } + } + } + } + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(java.util.Locale.US, bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00543.java b/OWASP DATASET/BenchmarkTest00543.java new file mode 100644 index 0000000000000000000000000000000000000000..2fa3f24739621b165cf3ef9e3a59e45e422bafe0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00543.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-00/BenchmarkTest00543") +public class BenchmarkTest00543 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00543")) { + param = name; + flag = false; + } + } + } + } + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00544.java b/OWASP DATASET/BenchmarkTest00544.java new file mode 100644 index 0000000000000000000000000000000000000000..961df4d70bda92c944bd8c870735fa09dbcc0350 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00544.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00544") +public class BenchmarkTest00544 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00544")) { + param = name; + flag = false; + } + } + } + } + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar.toCharArray()); + } +} diff --git a/OWASP DATASET/BenchmarkTest00545.java b/OWASP DATASET/BenchmarkTest00545.java new file mode 100644 index 0000000000000000000000000000000000000000..e80b61b2fa74a738f0880fe134c029f414b033e3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00545.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00545") +public class BenchmarkTest00545 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00545")) { + param = name; + flag = false; + } + } + } + } + + // Chain a bunch of propagators in sequence + String a80566 = param; // assign + StringBuilder b80566 = new StringBuilder(a80566); // stick in stringbuilder + b80566.append(" SafeStuff"); // append some safe content + b80566.replace( + b80566.length() - "Chars".length(), + b80566.length(), + "Chars"); // replace some of the end content + java.util.HashMap map80566 = new java.util.HashMap(); + map80566.put("key80566", b80566.toString()); // put in a collection + String c80566 = (String) map80566.get("key80566"); // get it back out + String d80566 = c80566.substring(0, c80566.length() - 1); // extract most of it + String e80566 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d80566.getBytes()))); // B64 encode and decode it + String f80566 = e80566.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g80566 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g80566); // reflection + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar.toCharArray()); + } +} diff --git a/OWASP DATASET/BenchmarkTest00546.java b/OWASP DATASET/BenchmarkTest00546.java new file mode 100644 index 0000000000000000000000000000000000000000..898160f8a68d15b0b94a389c2ba0af6b4d184731 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00546.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00546") +public class BenchmarkTest00546 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00546")) { + param = name; + flag = false; + } + } + } + } + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00547.java b/OWASP DATASET/BenchmarkTest00547.java new file mode 100644 index 0000000000000000000000000000000000000000..fd1b7bd0082f546b022897539b4e611c8d384d81 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00547.java @@ -0,0 +1,67 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00547") +public class BenchmarkTest00547 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00547")) { + param = name; + flag = false; + } + } + } + } + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(java.util.Locale.US, bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00548.java b/OWASP DATASET/BenchmarkTest00548.java new file mode 100644 index 0000000000000000000000000000000000000000..0aefe4de9e347e24b6586bbd97103f592935a03b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00548.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00548") +public class BenchmarkTest00548 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00548")) { + param = name; + flag = false; + } + } + } + } + + // Chain a bunch of propagators in sequence + String a52901 = param; // assign + StringBuilder b52901 = new StringBuilder(a52901); // stick in stringbuilder + b52901.append(" SafeStuff"); // append some safe content + b52901.replace( + b52901.length() - "Chars".length(), + b52901.length(), + "Chars"); // replace some of the end content + java.util.HashMap map52901 = new java.util.HashMap(); + map52901.put("key52901", b52901.toString()); // put in a collection + String c52901 = (String) map52901.get("key52901"); // get it back out + String d52901 = c52901.substring(0, c52901.length() - 1); // extract most of it + String e52901 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d52901.getBytes()))); // B64 encode and decode it + String f52901 = e52901.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g52901 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g52901); // reflection + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {bar, "b"}; + response.getWriter().printf("Formatted like: %1$s and %2$s.", obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00549.java b/OWASP DATASET/BenchmarkTest00549.java new file mode 100644 index 0000000000000000000000000000000000000000..edfc6c79053bbd12dcc4b52412398bd7069154c7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00549.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00549") +public class BenchmarkTest00549 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00549")) { + param = name; + flag = false; + } + } + } + } + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar.toCharArray()); + } +} diff --git a/OWASP DATASET/BenchmarkTest00550.java b/OWASP DATASET/BenchmarkTest00550.java new file mode 100644 index 0000000000000000000000000000000000000000..ac568138263112aca4d75dfac7faa1d1761d08f2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00550.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00550") +public class BenchmarkTest00550 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00550")) { + param = name; + flag = false; + } + } + } + } + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar.toCharArray()); + } +} diff --git a/OWASP DATASET/BenchmarkTest00551.java b/OWASP DATASET/BenchmarkTest00551.java new file mode 100644 index 0000000000000000000000000000000000000000..f5b7944fac01d8b1c9f03567f75b51f22ed3ad7d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00551.java @@ -0,0 +1,65 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00551") +public class BenchmarkTest00551 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00551")) { + param = name; + flag = false; + } + } + } + } + + String bar = param; + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00552.java b/OWASP DATASET/BenchmarkTest00552.java new file mode 100644 index 0000000000000000000000000000000000000000..bcdf8915734523fcb108b893eae75e02ddc31c8c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00552.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00552") +public class BenchmarkTest00552 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00552")) { + param = name; + flag = false; + } + } + } + } + + String bar = "safe!"; + java.util.HashMap map63597 = new java.util.HashMap(); + map63597.put("keyA-63597", "a-Value"); // put some stuff in the collection + map63597.put("keyB-63597", param); // put it in a collection + map63597.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map63597.get("keyB-63597"); // get it back out + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00553.java b/OWASP DATASET/BenchmarkTest00553.java new file mode 100644 index 0000000000000000000000000000000000000000..6a9c6a45cc08e30695dab41c974ccffc626ec30b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00553.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00553") +public class BenchmarkTest00553 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00553")) { + param = name; + flag = false; + } + } + } + } + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00554.java b/OWASP DATASET/BenchmarkTest00554.java new file mode 100644 index 0000000000000000000000000000000000000000..e65fe1bd9102cb0fab389fa8a87a0e5575b63dc8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00554.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00554") +public class BenchmarkTest00554 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00554")) { + param = name; + flag = false; + } + } + } + } + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00555.java b/OWASP DATASET/BenchmarkTest00555.java new file mode 100644 index 0000000000000000000000000000000000000000..576793e002df79c5b6710ebf98d4665e6151604f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00555.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00555") +public class BenchmarkTest00555 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00555")) { + param = name; + flag = false; + } + } + } + } + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar.toCharArray()); + } +} diff --git a/OWASP DATASET/BenchmarkTest00556.java b/OWASP DATASET/BenchmarkTest00556.java new file mode 100644 index 0000000000000000000000000000000000000000..16b466c3e908265665074f0b0f3b41c9a642530b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00556.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00556") +public class BenchmarkTest00556 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00556")) { + param = name; + flag = false; + } + } + } + } + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00557.java b/OWASP DATASET/BenchmarkTest00557.java new file mode 100644 index 0000000000000000000000000000000000000000..e01e78f2e7fb32e8f5052ee3f456163514a238c0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00557.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00557") +public class BenchmarkTest00557 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00557")) { + param = name; + flag = false; + } + } + } + } + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar, 0, length); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00558.java b/OWASP DATASET/BenchmarkTest00558.java new file mode 100644 index 0000000000000000000000000000000000000000..3371dbbc1987b1c012c06518834ffb806aa2c1a6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00558.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00558") +public class BenchmarkTest00558 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00558")) { + param = name; + flag = false; + } + } + } + } + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00559.java b/OWASP DATASET/BenchmarkTest00559.java new file mode 100644 index 0000000000000000000000000000000000000000..700cf87216057bcebb551b3535bc352510332a2d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00559.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00559") +public class BenchmarkTest00559 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00559")) { + param = name; + flag = false; + } + } + } + } + + // Chain a bunch of propagators in sequence + String a39502 = param; // assign + StringBuilder b39502 = new StringBuilder(a39502); // stick in stringbuilder + b39502.append(" SafeStuff"); // append some safe content + b39502.replace( + b39502.length() - "Chars".length(), + b39502.length(), + "Chars"); // replace some of the end content + java.util.HashMap map39502 = new java.util.HashMap(); + map39502.put("key39502", b39502.toString()); // put in a collection + String c39502 = (String) map39502.get("key39502"); // get it back out + String d39502 = c39502.substring(0, c39502.length() - 1); // extract most of it + String e39502 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d39502.getBytes()))); // B64 encode and decode it + String f39502 = e39502.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g39502 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g39502); // reflection + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00560.java b/OWASP DATASET/BenchmarkTest00560.java new file mode 100644 index 0000000000000000000000000000000000000000..64e5ad02c30bebdf549ee6c72a1a17a8b3e06b16 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00560.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00560") +public class BenchmarkTest00560 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00560")) { + param = name; + flag = false; + } + } + } + } + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + double value = new java.util.Random().nextDouble(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Donna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextDouble() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00561.java b/OWASP DATASET/BenchmarkTest00561.java new file mode 100644 index 0000000000000000000000000000000000000000..05dd11209f6b1cc4e9dc455c6e722d8277cde786 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00561.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00561") +public class BenchmarkTest00561 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00561")) { + param = name; + flag = false; + } + } + } + } + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + float rand = new java.util.Random().nextFloat(); + String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "Floyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00562.java b/OWASP DATASET/BenchmarkTest00562.java new file mode 100644 index 0000000000000000000000000000000000000000..8a9668a12f1f97ad209f14199efdf3ded6d60a34 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00562.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00562") +public class BenchmarkTest00562 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00562")) { + param = name; + flag = false; + } + } + } + } + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + float rand = new java.util.Random().nextFloat(); + String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "Floyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00563.java b/OWASP DATASET/BenchmarkTest00563.java new file mode 100644 index 0000000000000000000000000000000000000000..32f8eb0ad216a6a5bf52952acc7e1e7e6791527b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00563.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00563") +public class BenchmarkTest00563 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00563")) { + param = name; + flag = false; + } + } + } + } + + String bar = param; + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00564.java b/OWASP DATASET/BenchmarkTest00564.java new file mode 100644 index 0000000000000000000000000000000000000000..8f79179b32281c0e45acfb078025cc06ce4b3b99 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00564.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00564") +public class BenchmarkTest00564 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00564")) { + param = name; + flag = false; + } + } + } + } + + StringBuilder sbxyz41882 = new StringBuilder(param); + String bar = sbxyz41882.append("_SafeStuff").toString(); + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00565.java b/OWASP DATASET/BenchmarkTest00565.java new file mode 100644 index 0000000000000000000000000000000000000000..eafe34dd52d6a34fbe4e3f75c6fcf16e344c08d1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00565.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest00565") +public class BenchmarkTest00565 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00565")) { + param = name; + flag = false; + } + } + } + } + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00566.java b/OWASP DATASET/BenchmarkTest00566.java new file mode 100644 index 0000000000000000000000000000000000000000..a810b0257deb96c76dc49825aed7cdcff2d0f633 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00566.java @@ -0,0 +1,93 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest00566") +public class BenchmarkTest00566 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00566")) { + param = name; + flag = false; + } + } + } + } + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00567.java b/OWASP DATASET/BenchmarkTest00567.java new file mode 100644 index 0000000000000000000000000000000000000000..1ced43750aee6509a68e887c43f7f718e86aa46b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00567.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00567") +public class BenchmarkTest00567 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00567")) { + param = name; + flag = false; + } + } + } + } + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00568.java b/OWASP DATASET/BenchmarkTest00568.java new file mode 100644 index 0000000000000000000000000000000000000000..394eb613ea2f5063e6b68517d716ddb4cfd821d2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00568.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00568") +public class BenchmarkTest00568 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00568")) { + param = name; + flag = false; + } + } + } + } + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00569.java b/OWASP DATASET/BenchmarkTest00569.java new file mode 100644 index 0000000000000000000000000000000000000000..060233e691d7d7d7cbb3774a800ba04e4fdcb7c1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00569.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00569") +public class BenchmarkTest00569 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00569")) { + param = name; + flag = false; + } + } + } + } + + // Chain a bunch of propagators in sequence + String a6821 = param; // assign + StringBuilder b6821 = new StringBuilder(a6821); // stick in stringbuilder + b6821.append(" SafeStuff"); // append some safe content + b6821.replace( + b6821.length() - "Chars".length(), + b6821.length(), + "Chars"); // replace some of the end content + java.util.HashMap map6821 = new java.util.HashMap(); + map6821.put("key6821", b6821.toString()); // put in a collection + String c6821 = (String) map6821.get("key6821"); // get it back out + String d6821 = c6821.substring(0, c6821.length() - 1); // extract most of it + String e6821 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d6821.getBytes()))); // B64 encode and decode it + String f6821 = e6821.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g6821 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g6821); // reflection + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00570.java b/OWASP DATASET/BenchmarkTest00570.java new file mode 100644 index 0000000000000000000000000000000000000000..09006b5445513f35b1ba383eba9af24f6baaf366 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00570.java @@ -0,0 +1,90 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00570") +public class BenchmarkTest00570 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00570")) { + param = name; + flag = false; + } + } + } + } + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00571.java b/OWASP DATASET/BenchmarkTest00571.java new file mode 100644 index 0000000000000000000000000000000000000000..34b39a81c73f55f9972dd0dedb1f15e95a1d47d3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00571.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00571") +public class BenchmarkTest00571 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00571")) { + param = name; + flag = false; + } + } + } + } + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00572.java b/OWASP DATASET/BenchmarkTest00572.java new file mode 100644 index 0000000000000000000000000000000000000000..791673d4d28c344eb3ac8c075731db9ef06e9ec5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00572.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00572") +public class BenchmarkTest00572 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00572")) { + param = name; + flag = false; + } + } + } + } + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00573.java b/OWASP DATASET/BenchmarkTest00573.java new file mode 100644 index 0000000000000000000000000000000000000000..cc82f2820b47111ee98308f09c0b1b44dfd90cf5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00573.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00573") +public class BenchmarkTest00573 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00573")) { + param = name; + flag = false; + } + } + } + } + + String bar = param; + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00574.java b/OWASP DATASET/BenchmarkTest00574.java new file mode 100644 index 0000000000000000000000000000000000000000..92d29aba9de577aa5a642ea0d575d11947e85853 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00574.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00574") +public class BenchmarkTest00574 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00574")) { + param = name; + flag = false; + } + } + } + } + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00575.java b/OWASP DATASET/BenchmarkTest00575.java new file mode 100644 index 0000000000000000000000000000000000000000..6a8ec277fc8c2c00bfa1af30fb96f81d5795e7a4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00575.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00575") +public class BenchmarkTest00575 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00575")) { + param = name; + flag = false; + } + } + } + } + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = + r.exec(cmd + bar, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00576.java b/OWASP DATASET/BenchmarkTest00576.java new file mode 100644 index 0000000000000000000000000000000000000000..1444ae7414d6fdcc9661c65a9fe3761d44a04f6e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00576.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00576") +public class BenchmarkTest00576 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00576")) { + param = name; + flag = false; + } + } + } + } + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = + r.exec(cmd + bar, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00577.java b/OWASP DATASET/BenchmarkTest00577.java new file mode 100644 index 0000000000000000000000000000000000000000..025c622609d0f65f0936c6c24ce9c8b72c1e63c9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00577.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00577") +public class BenchmarkTest00577 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00577")) { + param = name; + flag = false; + } + } + } + } + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00578.java b/OWASP DATASET/BenchmarkTest00578.java new file mode 100644 index 0000000000000000000000000000000000000000..13f136b7fa1c13e1f651c48da716ab90f1a976ac --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00578.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00578") +public class BenchmarkTest00578 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00578")) { + param = name; + flag = false; + } + } + } + } + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + getNextNumber(numGen, randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeBystander"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } + + void getNextNumber(java.util.Random generator, byte[] barray) { + generator.nextBytes(barray); + } +} diff --git a/OWASP DATASET/BenchmarkTest00579.java b/OWASP DATASET/BenchmarkTest00579.java new file mode 100644 index 0000000000000000000000000000000000000000..4f006bf46344b111d72ba7935a87b0b36200e490 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00579.java @@ -0,0 +1,133 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00579") +public class BenchmarkTest00579 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00579")) { + param = name; + flag = false; + } + } + } + } + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + getNextNumber(numGen, randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeBystander"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } + + void getNextNumber(java.util.Random generator, byte[] barray) { + generator.nextBytes(barray); + } +} diff --git a/OWASP DATASET/BenchmarkTest00580.java b/OWASP DATASET/BenchmarkTest00580.java new file mode 100644 index 0000000000000000000000000000000000000000..b4cf18f54d4d6ca769767dd109e3eba62b3793cb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00580.java @@ -0,0 +1,126 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00580") +public class BenchmarkTest00580 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00580")) { + param = name; + flag = false; + } + } + } + } + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00581.java b/OWASP DATASET/BenchmarkTest00581.java new file mode 100644 index 0000000000000000000000000000000000000000..aa36be413440e4c8fd3057eb9f575e1ebd316c85 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00581.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00581") +public class BenchmarkTest00581 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00581")) { + param = name; + flag = false; + } + } + } + } + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00582.java b/OWASP DATASET/BenchmarkTest00582.java new file mode 100644 index 0000000000000000000000000000000000000000..5dc0548f2eb32d700540cbfcb9d2e188440424b2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00582.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00582") +public class BenchmarkTest00582 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00582")) { + param = name; + flag = false; + } + } + } + } + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + double rand = getNextNumber(numGen); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonatella"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } + + double getNextNumber(java.util.Random generator) { + return generator.nextDouble(); + } +} diff --git a/OWASP DATASET/BenchmarkTest00583.java b/OWASP DATASET/BenchmarkTest00583.java new file mode 100644 index 0000000000000000000000000000000000000000..37c8b5733a46217cb9b93d2bb24e5205b55d0a52 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00583.java @@ -0,0 +1,125 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00583") +public class BenchmarkTest00583 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00583")) { + param = name; + flag = false; + } + } + } + } + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00584.java b/OWASP DATASET/BenchmarkTest00584.java new file mode 100644 index 0000000000000000000000000000000000000000..5bf448e1602d14d77931249b19b18457c9a806d2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00584.java @@ -0,0 +1,125 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00584") +public class BenchmarkTest00584 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00584")) { + param = name; + flag = false; + } + } + } + } + + String bar = "safe!"; + java.util.HashMap map23020 = new java.util.HashMap(); + map23020.put("keyA-23020", "a_Value"); // put some stuff in the collection + map23020.put("keyB-23020", param); // put it in a collection + map23020.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map23020.get("keyB-23020"); // get it back out + bar = (String) map23020.get("keyA-23020"); // get safe value back out + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00585.java b/OWASP DATASET/BenchmarkTest00585.java new file mode 100644 index 0000000000000000000000000000000000000000..9217ff2497b07bfe59df73c6b811eca7db6f5a4d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00585.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00585") +public class BenchmarkTest00585 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00585")) { + param = name; + flag = false; + } + } + } + } + + StringBuilder sbxyz49441 = new StringBuilder(param); + String bar = sbxyz49441.append("_SafeStuff").toString(); + + try { + int randNumber = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "SafeInga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt(int) - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt(int) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00586.java b/OWASP DATASET/BenchmarkTest00586.java new file mode 100644 index 0000000000000000000000000000000000000000..09e2312affb13dc1bef5897b9348040f45b3db0b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00586.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00586") +public class BenchmarkTest00586 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00586")) { + param = name; + flag = false; + } + } + } + } + + String bar = "safe!"; + java.util.HashMap map58886 = new java.util.HashMap(); + map58886.put("keyA-58886", "a_Value"); // put some stuff in the collection + map58886.put("keyB-58886", param); // put it in a collection + map58886.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map58886.get("keyB-58886"); // get it back out + bar = (String) map58886.get("keyA-58886"); // get safe value back out + + // javax.servlet.http.HttpSession.putValue(java.lang.String^,java.lang.Object) + request.getSession().putValue(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: 10340 saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00587.java b/OWASP DATASET/BenchmarkTest00587.java new file mode 100644 index 0000000000000000000000000000000000000000..128abb8b53bacb5e69b4e1e720851e4514b433ec --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00587.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00587") +public class BenchmarkTest00587 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00587")) { + param = name; + flag = false; + } + } + } + } + + String bar = "safe!"; + java.util.HashMap map44465 = new java.util.HashMap(); + map44465.put("keyA-44465", "a-Value"); // put some stuff in the collection + map44465.put("keyB-44465", param); // put it in a collection + map44465.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map44465.get("keyB-44465"); // get it back out + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String^,java.lang.Object) + request.getSession().setAttribute(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: '10340' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00588.java b/OWASP DATASET/BenchmarkTest00588.java new file mode 100644 index 0000000000000000000000000000000000000000..2e6470a3ce4bdceab847618c6cbc5b991c75f3f9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00588.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00588") +public class BenchmarkTest00588 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00588")) { + param = name; + flag = false; + } + } + } + } + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String^,java.lang.Object) + request.getSession().setAttribute(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: '10340' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00589.java b/OWASP DATASET/BenchmarkTest00589.java new file mode 100644 index 0000000000000000000000000000000000000000..9952780baadb096950055ab1a0e584a168544297 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00589.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00589") +public class BenchmarkTest00589 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00589")) { + param = name; + flag = false; + } + } + } + } + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00590.java b/OWASP DATASET/BenchmarkTest00590.java new file mode 100644 index 0000000000000000000000000000000000000000..cba00d5b4d46405370bf1fdcca6bc39f04e232ad --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00590.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00590") +public class BenchmarkTest00590 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00590")) { + param = name; + flag = false; + } + } + } + } + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00591.java b/OWASP DATASET/BenchmarkTest00591.java new file mode 100644 index 0000000000000000000000000000000000000000..b9e3d544a6ac61ffbf74cca8be17d6e5f843bc0a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00591.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00591") +public class BenchmarkTest00591 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00591")) { + param = name; + flag = false; + } + } + } + } + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00592.java b/OWASP DATASET/BenchmarkTest00592.java new file mode 100644 index 0000000000000000000000000000000000000000..15b267edc6dfe20166dff2946b63a18a7bc993f1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00592.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00592") +public class BenchmarkTest00592 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00592")) { + param = name; + flag = false; + } + } + } + } + + // Chain a bunch of propagators in sequence + String a36502 = param; // assign + StringBuilder b36502 = new StringBuilder(a36502); // stick in stringbuilder + b36502.append(" SafeStuff"); // append some safe content + b36502.replace( + b36502.length() - "Chars".length(), + b36502.length(), + "Chars"); // replace some of the end content + java.util.HashMap map36502 = new java.util.HashMap(); + map36502.put("key36502", b36502.toString()); // put in a collection + String c36502 = (String) map36502.get("key36502"); // get it back out + String d36502 = c36502.substring(0, c36502.length() - 1); // extract most of it + String e36502 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d36502.getBytes()))); // B64 encode and decode it + String f36502 = e36502.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g36502 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g36502); // reflection + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00593.java b/OWASP DATASET/BenchmarkTest00593.java new file mode 100644 index 0000000000000000000000000000000000000000..d0b3de8ed22dfdc59d1ed3df7a70047ae2a9deb5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00593.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00593") +public class BenchmarkTest00593 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00593")) { + param = name; + flag = false; + } + } + } + } + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00594.java b/OWASP DATASET/BenchmarkTest00594.java new file mode 100644 index 0000000000000000000000000000000000000000..a6f8dda124cdb7d465a1c3f3948babd0e6309bf3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00594.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00594") +public class BenchmarkTest00594 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00594")) { + param = name; + flag = false; + } + } + } + } + + String bar = "safe!"; + java.util.HashMap map29056 = new java.util.HashMap(); + map29056.put("keyA-29056", "a-Value"); // put some stuff in the collection + map29056.put("keyB-29056", param); // put it in a collection + map29056.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map29056.get("keyB-29056"); // get it back out + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, new String[] {"Column1", "Column2"}); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00595.java b/OWASP DATASET/BenchmarkTest00595.java new file mode 100644 index 0000000000000000000000000000000000000000..b21eaad7e2b01061f30fec55ec80643f63aab70a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00595.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00595") +public class BenchmarkTest00595 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00595")) { + param = name; + flag = false; + } + } + } + } + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, new String[] {"Column1", "Column2"}); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00596.java b/OWASP DATASET/BenchmarkTest00596.java new file mode 100644 index 0000000000000000000000000000000000000000..510dd017d805ec79f379048eefafad496f49fc30 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00596.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00596") +public class BenchmarkTest00596 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00596")) { + param = name; + flag = false; + } + } + } + } + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List> list = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForList(sql); + response.getWriter().println("Your results are:
"); + + // System.out.println("Your results are"); + + for (Object o : list) { + response.getWriter() + .println( + org.owasp.esapi.ESAPI.encoder().encodeForHTML(o.toString()) + + "
"); + // System.out.println(o.toString()); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00597.java b/OWASP DATASET/BenchmarkTest00597.java new file mode 100644 index 0000000000000000000000000000000000000000..aa5589e0c33f068abf833735b35805ea13decc8a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00597.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00597") +public class BenchmarkTest00597 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00597")) { + param = name; + flag = false; + } + } + } + } + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List> list = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForList(sql); + response.getWriter().println("Your results are:
"); + + // System.out.println("Your results are"); + + for (Object o : list) { + response.getWriter() + .println( + org.owasp.esapi.ESAPI.encoder().encodeForHTML(o.toString()) + + "
"); + // System.out.println(o.toString()); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00598.java b/OWASP DATASET/BenchmarkTest00598.java new file mode 100644 index 0000000000000000000000000000000000000000..0141f393fd4a95d45269859276c49a73e2bd968d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00598.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00598") +public class BenchmarkTest00598 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00598")) { + param = name; + flag = false; + } + } + } + } + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + String sql = + "SELECT TOP 1 userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.Map results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForMap(sql); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(results.toString())); + // System.out.println(results.toString()); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00599.java b/OWASP DATASET/BenchmarkTest00599.java new file mode 100644 index 0000000000000000000000000000000000000000..5c2b1865e985c7be1ef332872c6927318cdb5c76 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00599.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00599") +public class BenchmarkTest00599 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00599")) { + param = name; + flag = false; + } + } + } + } + + // Chain a bunch of propagators in sequence + String a99467 = param; // assign + StringBuilder b99467 = new StringBuilder(a99467); // stick in stringbuilder + b99467.append(" SafeStuff"); // append some safe content + b99467.replace( + b99467.length() - "Chars".length(), + b99467.length(), + "Chars"); // replace some of the end content + java.util.HashMap map99467 = new java.util.HashMap(); + map99467.put("key99467", b99467.toString()); // put in a collection + String c99467 = (String) map99467.get("key99467"); // get it back out + String d99467 = c99467.substring(0, c99467.length() - 1); // extract most of it + String e99467 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d99467.getBytes()))); // B64 encode and decode it + String f99467 = e99467.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g99467 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g99467); // reflection + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00600.java b/OWASP DATASET/BenchmarkTest00600.java new file mode 100644 index 0000000000000000000000000000000000000000..d9af4eeb8e8b4f36b042fed46f8cd998a3d513f4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00600.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00600") +public class BenchmarkTest00600 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00600")) { + param = name; + flag = false; + } + } + } + } + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00601.java b/OWASP DATASET/BenchmarkTest00601.java new file mode 100644 index 0000000000000000000000000000000000000000..63b72dc4b572f6332d627526f21901fb94f6cd6d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00601.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00601") +public class BenchmarkTest00601 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00601")) { + param = name; + flag = false; + } + } + } + } + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.addBatch(sql); + int[] counts = statement.executeBatch(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(sql, counts, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00602.java b/OWASP DATASET/BenchmarkTest00602.java new file mode 100644 index 0000000000000000000000000000000000000000..1442ed6d366fd3e3fc49ae8a81f353ee67376c4d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00602.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00602") +public class BenchmarkTest00602 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00602")) { + param = name; + flag = false; + } + } + } + } + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00603.java b/OWASP DATASET/BenchmarkTest00603.java new file mode 100644 index 0000000000000000000000000000000000000000..ab629015206eafd1497ed325317e81e81f24e4cd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00603.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00603") +public class BenchmarkTest00603 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00603")) { + param = name; + flag = false; + } + } + } + } + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00604.java b/OWASP DATASET/BenchmarkTest00604.java new file mode 100644 index 0000000000000000000000000000000000000000..362b07436c8e5c6c67761bd34a21ee8fd4f308fe --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00604.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00604") +public class BenchmarkTest00604 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00604")) { + param = name; + flag = false; + } + } + } + } + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + java.sql.ResultSet rs = statement.executeQuery(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00605.java b/OWASP DATASET/BenchmarkTest00605.java new file mode 100644 index 0000000000000000000000000000000000000000..8cedb8b166d5bd733f5753001d9dc292cd81b70a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00605.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00605") +public class BenchmarkTest00605 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00605")) { + param = name; + flag = false; + } + } + } + } + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00606.java b/OWASP DATASET/BenchmarkTest00606.java new file mode 100644 index 0000000000000000000000000000000000000000..0a8aba5f62965e6bad303560571e6b0d779e6ef7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00606.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00606") +public class BenchmarkTest00606 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00606")) { + param = name; + flag = false; + } + } + } + } + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00607.java b/OWASP DATASET/BenchmarkTest00607.java new file mode 100644 index 0000000000000000000000000000000000000000..cdecc16dd1490b8170312907f7401a124723f27c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00607.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest00607") +public class BenchmarkTest00607 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest00607")) { + param = name; + flag = false; + } + } + } + } + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + String result = xp.evaluate(expression, xmlDocument); + + response.getWriter().println("Your query results are: " + result + "
"); + + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00608.java b/OWASP DATASET/BenchmarkTest00608.java new file mode 100644 index 0000000000000000000000000000000000000000..d6f39c7443ecd79526e0293cb73d50a0cbaacdb3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00608.java @@ -0,0 +1,160 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00608") +public class BenchmarkTest00608 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00608"); + if (param == null) param = ""; + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "DES/CBC/PKCS5PADDING", java.security.Security.getProvider("SunJCE")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00609.java b/OWASP DATASET/BenchmarkTest00609.java new file mode 100644 index 0000000000000000000000000000000000000000..315f401d3785feea8ef2dae65b6cc5ddf137600d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00609.java @@ -0,0 +1,152 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00609") +public class BenchmarkTest00609 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00609"); + if (param == null) param = ""; + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "DES/CBC/PKCS5PADDING", java.security.Security.getProvider("SunJCE")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00610.java b/OWASP DATASET/BenchmarkTest00610.java new file mode 100644 index 0000000000000000000000000000000000000000..2d0e15dbddb3fdaf992be26f87b9db2b2067da94 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00610.java @@ -0,0 +1,171 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00610") +public class BenchmarkTest00610 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00610"); + if (param == null) param = ""; + + // Chain a bunch of propagators in sequence + String a51289 = param; // assign + StringBuilder b51289 = new StringBuilder(a51289); // stick in stringbuilder + b51289.append(" SafeStuff"); // append some safe content + b51289.replace( + b51289.length() - "Chars".length(), + b51289.length(), + "Chars"); // replace some of the end content + java.util.HashMap map51289 = new java.util.HashMap(); + map51289.put("key51289", b51289.toString()); // put in a collection + String c51289 = (String) map51289.get("key51289"); // get it back out + String d51289 = c51289.substring(0, c51289.length() - 1); // extract most of it + String e51289 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d51289.getBytes()))); // B64 encode and decode it + String f51289 = e51289.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g51289 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g51289); // reflection + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "DES/CBC/PKCS5PADDING", java.security.Security.getProvider("SunJCE")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00611.java b/OWASP DATASET/BenchmarkTest00611.java new file mode 100644 index 0000000000000000000000000000000000000000..bad784c9c2f047350bbd52530c91f46e5f3b5b8e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00611.java @@ -0,0 +1,155 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00611") +public class BenchmarkTest00611 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00611"); + if (param == null) param = ""; + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "DES/CBC/PKCS5PADDING", java.security.Security.getProvider("SunJCE")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00612.java b/OWASP DATASET/BenchmarkTest00612.java new file mode 100644 index 0000000000000000000000000000000000000000..4649ecb72fc3f3c45d87b4b06df4cd512f6a7dbf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00612.java @@ -0,0 +1,156 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00612") +public class BenchmarkTest00612 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00612"); + if (param == null) param = ""; + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00613.java b/OWASP DATASET/BenchmarkTest00613.java new file mode 100644 index 0000000000000000000000000000000000000000..df406bb74d1230aa856f099999dafd33c57bdeec --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00613.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00613") +public class BenchmarkTest00613 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00613"); + if (param == null) param = ""; + + String bar = "safe!"; + java.util.HashMap map67704 = new java.util.HashMap(); + map67704.put("keyA-67704", "a_Value"); // put some stuff in the collection + map67704.put("keyB-67704", param); // put it in a collection + map67704.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map67704.get("keyB-67704"); // get it back out + bar = (String) map67704.get("keyA-67704"); // get safe value back out + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = org.owasp.benchmark.helpers.Utils.getCipher(); + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00614.java b/OWASP DATASET/BenchmarkTest00614.java new file mode 100644 index 0000000000000000000000000000000000000000..6a90f194e15be27a593b235a81c85ad324a06cc8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00614.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00614") +public class BenchmarkTest00614 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00614"); + if (param == null) param = ""; + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00615.java b/OWASP DATASET/BenchmarkTest00615.java new file mode 100644 index 0000000000000000000000000000000000000000..e342d6f22759e444f299ad16bfadce5e1940498b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00615.java @@ -0,0 +1,126 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00615") +public class BenchmarkTest00615 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00615"); + if (param == null) param = ""; + + String bar = "safe!"; + java.util.HashMap map4123 = new java.util.HashMap(); + map4123.put("keyA-4123", "a_Value"); // put some stuff in the collection + map4123.put("keyB-4123", param); // put it in a collection + map4123.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map4123.get("keyB-4123"); // get it back out + bar = (String) map4123.get("keyA-4123"); // get safe value back out + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00616.java b/OWASP DATASET/BenchmarkTest00616.java new file mode 100644 index 0000000000000000000000000000000000000000..22b5fd3f273f0f373ea6fa92c3a85bb46387f060 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00616.java @@ -0,0 +1,111 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00616") +public class BenchmarkTest00616 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00616"); + if (param == null) param = ""; + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00617.java b/OWASP DATASET/BenchmarkTest00617.java new file mode 100644 index 0000000000000000000000000000000000000000..ae39550688624020756ae1aa7be17ead17f8938b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00617.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00617") +public class BenchmarkTest00617 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00617"); + if (param == null) param = ""; + + StringBuilder sbxyz57328 = new StringBuilder(param); + String bar = sbxyz57328.append("_SafeStuff").toString(); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00618.java b/OWASP DATASET/BenchmarkTest00618.java new file mode 100644 index 0000000000000000000000000000000000000000..bb09fe37a845cf18ff191a4e5cc18f76b0c40d4c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00618.java @@ -0,0 +1,126 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00618") +public class BenchmarkTest00618 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00618"); + if (param == null) param = ""; + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + // java.security.SecureRandom random = new java.security.SecureRandom(); + // byte[] iv = random.generateSeed(16); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg2", "AES/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00619.java b/OWASP DATASET/BenchmarkTest00619.java new file mode 100644 index 0000000000000000000000000000000000000000..764a7886958929e8f32d2782737f2ed89a6f3d20 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00619.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00619") +public class BenchmarkTest00619 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00619"); + if (param == null) param = ""; + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00620.java b/OWASP DATASET/BenchmarkTest00620.java new file mode 100644 index 0000000000000000000000000000000000000000..2c997486e87a714f02bba065592cbef5f594216e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00620.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00620") +public class BenchmarkTest00620 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00620"); + if (param == null) param = ""; + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00621.java b/OWASP DATASET/BenchmarkTest00621.java new file mode 100644 index 0000000000000000000000000000000000000000..8bcbb255517c5bbb7cdfd87c0f49ae6735dd3d7b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00621.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00621") +public class BenchmarkTest00621 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00621"); + if (param == null) param = ""; + + // Chain a bunch of propagators in sequence + String a28566 = param; // assign + StringBuilder b28566 = new StringBuilder(a28566); // stick in stringbuilder + b28566.append(" SafeStuff"); // append some safe content + b28566.replace( + b28566.length() - "Chars".length(), + b28566.length(), + "Chars"); // replace some of the end content + java.util.HashMap map28566 = new java.util.HashMap(); + map28566.put("key28566", b28566.toString()); // put in a collection + String c28566 = (String) map28566.get("key28566"); // get it back out + String d28566 = c28566.substring(0, c28566.length() - 1); // extract most of it + String e28566 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d28566.getBytes()))); // B64 encode and decode it + String f28566 = e28566.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g28566 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g28566); // reflection + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00622.java b/OWASP DATASET/BenchmarkTest00622.java new file mode 100644 index 0000000000000000000000000000000000000000..f28bfafa2eece20ca67b62db733affd0357240ef --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00622.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00622") +public class BenchmarkTest00622 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00622"); + if (param == null) param = ""; + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + java.io.File fileTarget = + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR, bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00623.java b/OWASP DATASET/BenchmarkTest00623.java new file mode 100644 index 0000000000000000000000000000000000000000..6bebd29873fcbb1ccfa863fbbcc207136d128daf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00623.java @@ -0,0 +1,73 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00623") +public class BenchmarkTest00623 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00623"); + if (param == null) param = ""; + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + java.io.File fileTarget = new java.io.File(bar, "/Test.txt"); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00624.java b/OWASP DATASET/BenchmarkTest00624.java new file mode 100644 index 0000000000000000000000000000000000000000..3ec7f14c6635c38c7bc44fd4463f004c70fd2d18 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00624.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00624") +public class BenchmarkTest00624 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00624"); + if (param == null) param = ""; + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName), false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00625.java b/OWASP DATASET/BenchmarkTest00625.java new file mode 100644 index 0000000000000000000000000000000000000000..c754300307bb109d1323ce9f9cbfba0dca710eb4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00625.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00625") +public class BenchmarkTest00625 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00625"); + if (param == null) param = ""; + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName), false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00626.java b/OWASP DATASET/BenchmarkTest00626.java new file mode 100644 index 0000000000000000000000000000000000000000..0196e59a876f9cb3a3de7eb903a11bd5727a8f17 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00626.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00626") +public class BenchmarkTest00626 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00626"); + if (param == null) param = ""; + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName)); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00627.java b/OWASP DATASET/BenchmarkTest00627.java new file mode 100644 index 0000000000000000000000000000000000000000..4496fa890f56eddfe0f988b0733d75812f8958a9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00627.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00627") +public class BenchmarkTest00627 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00627"); + if (param == null) param = ""; + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName, false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00628.java b/OWASP DATASET/BenchmarkTest00628.java new file mode 100644 index 0000000000000000000000000000000000000000..9c2d50bc61fdb9416a394fe56d7fad0a6ad52f11 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00628.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00628") +public class BenchmarkTest00628 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00628"); + if (param == null) param = ""; + + // Chain a bunch of propagators in sequence + String a24315 = param; // assign + StringBuilder b24315 = new StringBuilder(a24315); // stick in stringbuilder + b24315.append(" SafeStuff"); // append some safe content + b24315.replace( + b24315.length() - "Chars".length(), + b24315.length(), + "Chars"); // replace some of the end content + java.util.HashMap map24315 = new java.util.HashMap(); + map24315.put("key24315", b24315.toString()); // put in a collection + String c24315 = (String) map24315.get("key24315"); // get it back out + String d24315 = c24315.substring(0, c24315.length() - 1); // extract most of it + String e24315 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d24315.getBytes()))); // B64 encode and decode it + String f24315 = e24315.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g24315 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g24315); // reflection + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00629.java b/OWASP DATASET/BenchmarkTest00629.java new file mode 100644 index 0000000000000000000000000000000000000000..cc57008dc0d83469a5e095644226d0e5ce442862 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00629.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00629") +public class BenchmarkTest00629 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00629"); + if (param == null) param = ""; + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + java.io.InputStream is = null; + + try { + java.nio.file.Path path = java.nio.file.Paths.get(fileName); + is = java.nio.file.Files.newInputStream(path, java.nio.file.StandardOpenOption.READ); + byte[] b = new byte[1000]; + int size = is.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + is.close(); + } catch (Exception e) { + System.out.println("Couldn't open InputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting InputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (is != null) { + try { + is.close(); + is = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00630.java b/OWASP DATASET/BenchmarkTest00630.java new file mode 100644 index 0000000000000000000000000000000000000000..8ab20cfcad68745c6bab52e270a10dcae66c406e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00630.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest00630") +public class BenchmarkTest00630 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00630"); + if (param == null) param = ""; + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person)(uid=" + bar + "))"; + + javax.naming.directory.DirContext ctx = ads.getDirContext(); + javax.naming.directory.InitialDirContext idc = + (javax.naming.directory.InitialDirContext) ctx; + boolean found = false; + javax.naming.NamingEnumeration results = + idc.search(base, filter, sc); + + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00631.java b/OWASP DATASET/BenchmarkTest00631.java new file mode 100644 index 0000000000000000000000000000000000000000..1ba1618f4bbe4b2fda911962dd8ccd41be6907a8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00631.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00631") +public class BenchmarkTest00631 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00631"); + if (param == null) param = ""; + + StringBuilder sbxyz28895 = new StringBuilder(param); + String bar = sbxyz28895.append("_SafeStuff").toString(); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("SHA1", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00632.java b/OWASP DATASET/BenchmarkTest00632.java new file mode 100644 index 0000000000000000000000000000000000000000..4228def0869c715198612727f6c33879ab75dbf0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00632.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00632") +public class BenchmarkTest00632 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00632"); + if (param == null) param = ""; + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("sha-384", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("sha-384", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00633.java b/OWASP DATASET/BenchmarkTest00633.java new file mode 100644 index 0000000000000000000000000000000000000000..a50ff65755afe696464a5d4cb749f276ceb41bf2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00633.java @@ -0,0 +1,131 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00633") +public class BenchmarkTest00633 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00633"); + if (param == null) param = ""; + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("sha-384", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("sha-384", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00634.java b/OWASP DATASET/BenchmarkTest00634.java new file mode 100644 index 0000000000000000000000000000000000000000..e978d5695fc6735e877acbcdcee573c3822e0a96 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00634.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00634") +public class BenchmarkTest00634 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00634"); + if (param == null) param = ""; + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00635.java b/OWASP DATASET/BenchmarkTest00635.java new file mode 100644 index 0000000000000000000000000000000000000000..ce0809d06c9e6bfaa19abeec80fbd21709dd43cc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00635.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00635") +public class BenchmarkTest00635 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00635"); + if (param == null) param = ""; + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00636.java b/OWASP DATASET/BenchmarkTest00636.java new file mode 100644 index 0000000000000000000000000000000000000000..cc5f8723c190cfc23651e623c72008a4eb27e1f7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00636.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00636") +public class BenchmarkTest00636 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00636"); + if (param == null) param = ""; + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00637.java b/OWASP DATASET/BenchmarkTest00637.java new file mode 100644 index 0000000000000000000000000000000000000000..24c033dc88c7b9db38a40107ffd4be03b88d5034 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00637.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00637") +public class BenchmarkTest00637 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00637"); + if (param == null) param = ""; + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00638.java b/OWASP DATASET/BenchmarkTest00638.java new file mode 100644 index 0000000000000000000000000000000000000000..c9132849ae1eb6da72570f50f4b65b742c73d69e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00638.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00638") +public class BenchmarkTest00638 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00638"); + if (param == null) param = ""; + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00639.java b/OWASP DATASET/BenchmarkTest00639.java new file mode 100644 index 0000000000000000000000000000000000000000..600ac89f93703001991ffc56606d145949196254 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00639.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00639") +public class BenchmarkTest00639 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00639"); + if (param == null) param = ""; + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00640.java b/OWASP DATASET/BenchmarkTest00640.java new file mode 100644 index 0000000000000000000000000000000000000000..8717ee8d5d4f598032fe0fac2162c761d6076a98 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00640.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00640") +public class BenchmarkTest00640 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00640"); + if (param == null) param = ""; + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00641.java b/OWASP DATASET/BenchmarkTest00641.java new file mode 100644 index 0000000000000000000000000000000000000000..e3243a7fbff005ba5c67c4e46578270a1374431c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00641.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00641") +public class BenchmarkTest00641 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00641"); + if (param == null) param = ""; + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00642.java b/OWASP DATASET/BenchmarkTest00642.java new file mode 100644 index 0000000000000000000000000000000000000000..044e0c034e9d2babd4a04141073697566eaf30c5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00642.java @@ -0,0 +1,63 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00642") +public class BenchmarkTest00642 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00642"); + if (param == null) param = ""; + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar.toCharArray()); + } +} diff --git a/OWASP DATASET/BenchmarkTest00643.java b/OWASP DATASET/BenchmarkTest00643.java new file mode 100644 index 0000000000000000000000000000000000000000..82665439fec7e11ac2af5fc85e0ff0b0370861d9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00643.java @@ -0,0 +1,54 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00643") +public class BenchmarkTest00643 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00643"); + if (param == null) param = ""; + + StringBuilder sbxyz31207 = new StringBuilder(param); + String bar = sbxyz31207.append("_SafeStuff").toString(); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar.toCharArray()); + } +} diff --git a/OWASP DATASET/BenchmarkTest00644.java b/OWASP DATASET/BenchmarkTest00644.java new file mode 100644 index 0000000000000000000000000000000000000000..8553c3b8fec051c6283f65def8da4b7c2b0813b2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00644.java @@ -0,0 +1,54 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00644") +public class BenchmarkTest00644 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00644"); + if (param == null) param = ""; + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00645.java b/OWASP DATASET/BenchmarkTest00645.java new file mode 100644 index 0000000000000000000000000000000000000000..8019ca2c4ccbe53c8815e52f020281df3472f2ba --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00645.java @@ -0,0 +1,56 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00645") +public class BenchmarkTest00645 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00645"); + if (param == null) param = ""; + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(java.util.Locale.US, bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00646.java b/OWASP DATASET/BenchmarkTest00646.java new file mode 100644 index 0000000000000000000000000000000000000000..ab43da700797370d7c41a402cb5e0af3d11c45cf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00646.java @@ -0,0 +1,63 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00646") +public class BenchmarkTest00646 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00646"); + if (param == null) param = ""; + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar.toCharArray()); + } +} diff --git a/OWASP DATASET/BenchmarkTest00647.java b/OWASP DATASET/BenchmarkTest00647.java new file mode 100644 index 0000000000000000000000000000000000000000..a1f46edb16988fb72abdb7613d580eb504e5cce9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00647.java @@ -0,0 +1,53 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00647") +public class BenchmarkTest00647 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00647"); + if (param == null) param = ""; + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00648.java b/OWASP DATASET/BenchmarkTest00648.java new file mode 100644 index 0000000000000000000000000000000000000000..442633f1d7f117e91eac9be6bb8770ca5ada2fba --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00648.java @@ -0,0 +1,53 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00648") +public class BenchmarkTest00648 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00648"); + if (param == null) param = ""; + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00649.java b/OWASP DATASET/BenchmarkTest00649.java new file mode 100644 index 0000000000000000000000000000000000000000..0c54d9387af70c57f5e3621d466471e287e37544 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00649.java @@ -0,0 +1,53 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00649") +public class BenchmarkTest00649 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00649"); + if (param == null) param = ""; + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar.toCharArray()); + } +} diff --git a/OWASP DATASET/BenchmarkTest00650.java b/OWASP DATASET/BenchmarkTest00650.java new file mode 100644 index 0000000000000000000000000000000000000000..98513050f33a535d0453cff7139952011bb170ab --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00650.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00650") +public class BenchmarkTest00650 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00650"); + if (param == null) param = ""; + + // Chain a bunch of propagators in sequence + String a17321 = param; // assign + StringBuilder b17321 = new StringBuilder(a17321); // stick in stringbuilder + b17321.append(" SafeStuff"); // append some safe content + b17321.replace( + b17321.length() - "Chars".length(), + b17321.length(), + "Chars"); // replace some of the end content + java.util.HashMap map17321 = new java.util.HashMap(); + map17321.put("key17321", b17321.toString()); // put in a collection + String c17321 = (String) map17321.get("key17321"); // get it back out + String d17321 = c17321.substring(0, c17321.length() - 1); // extract most of it + String e17321 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d17321.getBytes()))); // B64 encode and decode it + String f17321 = e17321.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g17321 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g17321); // reflection + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar.toCharArray()); + } +} diff --git a/OWASP DATASET/BenchmarkTest00651.java b/OWASP DATASET/BenchmarkTest00651.java new file mode 100644 index 0000000000000000000000000000000000000000..135ae6bc7656d6b27331193df0cefcf9b8a93863 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00651.java @@ -0,0 +1,62 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00651") +public class BenchmarkTest00651 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00651"); + if (param == null) param = ""; + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar, 0, length); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00652.java b/OWASP DATASET/BenchmarkTest00652.java new file mode 100644 index 0000000000000000000000000000000000000000..97efcb8d5fc0b1210782d895e4f22e4f01611a2f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00652.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00652") +public class BenchmarkTest00652 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00652"); + if (param == null) param = ""; + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + byte[] bytes = new byte[10]; + new java.util.Random().nextBytes(bytes); + String rememberMeKey = org.owasp.esapi.ESAPI.encoder().encodeForBase64(bytes, true); + + String user = "Byron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextBytes() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00653.java b/OWASP DATASET/BenchmarkTest00653.java new file mode 100644 index 0000000000000000000000000000000000000000..8ffa41afc118790b49e279a48b811a74ac152cd2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00653.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00653") +public class BenchmarkTest00653 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00653"); + if (param == null) param = ""; + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00654.java b/OWASP DATASET/BenchmarkTest00654.java new file mode 100644 index 0000000000000000000000000000000000000000..928ef5c5d6b924a74003e7d807a8d79531d9443f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00654.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00654") +public class BenchmarkTest00654 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00654"); + if (param == null) param = ""; + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00655.java b/OWASP DATASET/BenchmarkTest00655.java new file mode 100644 index 0000000000000000000000000000000000000000..2efbbcd2b34f13bbbb1b1cc4d3737f1c743a0fd3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00655.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest00655") +public class BenchmarkTest00655 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00655"); + if (param == null) param = ""; + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00656.java b/OWASP DATASET/BenchmarkTest00656.java new file mode 100644 index 0000000000000000000000000000000000000000..74218f25284571f86c58f0ae3c26f1632d96a873 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00656.java @@ -0,0 +1,58 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00656") +public class BenchmarkTest00656 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00656"); + if (param == null) param = ""; + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write("Parameter value: " + bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00657.java b/OWASP DATASET/BenchmarkTest00657.java new file mode 100644 index 0000000000000000000000000000000000000000..8c22ea1f9bf92dd715ad14681d21d7053810367c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00657.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00657") +public class BenchmarkTest00657 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00657"); + if (param == null) param = ""; + + String bar = "safe!"; + java.util.HashMap map27260 = new java.util.HashMap(); + map27260.put("keyA-27260", "a_Value"); // put some stuff in the collection + map27260.put("keyB-27260", param); // put it in a collection + map27260.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map27260.get("keyB-27260"); // get it back out + bar = (String) map27260.get("keyA-27260"); // get safe value back out + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00658.java b/OWASP DATASET/BenchmarkTest00658.java new file mode 100644 index 0000000000000000000000000000000000000000..7e6014dc761fb8cc60edbda773df802e2abc06dd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00658.java @@ -0,0 +1,73 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00658") +public class BenchmarkTest00658 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00658"); + if (param == null) param = ""; + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00659.java b/OWASP DATASET/BenchmarkTest00659.java new file mode 100644 index 0000000000000000000000000000000000000000..725a78f381fc23523dee7a0dbbb2ee3aea07b5a7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00659.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00659") +public class BenchmarkTest00659 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00659"); + if (param == null) param = ""; + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = + r.exec(cmd + bar, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00660.java b/OWASP DATASET/BenchmarkTest00660.java new file mode 100644 index 0000000000000000000000000000000000000000..056fa469258ef98127729a65aa96a093c9cc83c6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00660.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00660") +public class BenchmarkTest00660 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00660"); + if (param == null) param = ""; + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + double rand = getNextNumber(numGen); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonatella"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } + + double getNextNumber(java.util.Random generator) { + return generator.nextDouble(); + } +} diff --git a/OWASP DATASET/BenchmarkTest00661.java b/OWASP DATASET/BenchmarkTest00661.java new file mode 100644 index 0000000000000000000000000000000000000000..39175cc63b51d852bb76d9fa5b268deeb059c63f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00661.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00661") +public class BenchmarkTest00661 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00661"); + if (param == null) param = ""; + + String bar = param; + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00662.java b/OWASP DATASET/BenchmarkTest00662.java new file mode 100644 index 0000000000000000000000000000000000000000..428bf00966c7cae1d220c04705e79028d14f2dae --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00662.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00662") +public class BenchmarkTest00662 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00662"); + if (param == null) param = ""; + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00663.java b/OWASP DATASET/BenchmarkTest00663.java new file mode 100644 index 0000000000000000000000000000000000000000..32fb295f5a0455f2d51f04e9afdfb1d0f04cb0b2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00663.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00663") +public class BenchmarkTest00663 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00663"); + if (param == null) param = ""; + + String bar = "safe!"; + java.util.HashMap map67527 = new java.util.HashMap(); + map67527.put("keyA-67527", "a-Value"); // put some stuff in the collection + map67527.put("keyB-67527", param); // put it in a collection + map67527.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map67527.get("keyB-67527"); // get it back out + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00664.java b/OWASP DATASET/BenchmarkTest00664.java new file mode 100644 index 0000000000000000000000000000000000000000..e463ee69fc42fee45c8fe7742806ede64ef6b4df --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00664.java @@ -0,0 +1,126 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00664") +public class BenchmarkTest00664 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00664"); + if (param == null) param = ""; + + // Chain a bunch of propagators in sequence + String a87833 = param; // assign + StringBuilder b87833 = new StringBuilder(a87833); // stick in stringbuilder + b87833.append(" SafeStuff"); // append some safe content + b87833.replace( + b87833.length() - "Chars".length(), + b87833.length(), + "Chars"); // replace some of the end content + java.util.HashMap map87833 = new java.util.HashMap(); + map87833.put("key87833", b87833.toString()); // put in a collection + String c87833 = (String) map87833.get("key87833"); // get it back out + String d87833 = c87833.substring(0, c87833.length() - 1); // extract most of it + String e87833 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d87833.getBytes()))); // B64 encode and decode it + String f87833 = e87833.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g87833 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g87833); // reflection + + try { + float rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextFloat(); + String rememberMeKey = + Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeFloyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextFloat() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextFloat() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00665.java b/OWASP DATASET/BenchmarkTest00665.java new file mode 100644 index 0000000000000000000000000000000000000000..49e1601ab63bbece8ba2897a54c24121845ebd1d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00665.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00665") +public class BenchmarkTest00665 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00665"); + if (param == null) param = ""; + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + try { + double stuff = java.security.SecureRandom.getInstance("SHA1PRNG").nextGaussian(); + String rememberMeKey = + Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "SafeGayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextGaussian() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextGaussian() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00666.java b/OWASP DATASET/BenchmarkTest00666.java new file mode 100644 index 0000000000000000000000000000000000000000..475f28e55e2a6ec28e4256ab218b3bb2051a9363 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00666.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00666") +public class BenchmarkTest00666 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00666"); + if (param == null) param = ""; + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz65591 = new StringBuilder(param); + bar = sbxyz65591.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + try { + double stuff = java.security.SecureRandom.getInstance("SHA1PRNG").nextGaussian(); + String rememberMeKey = + Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "SafeGayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextGaussian() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextGaussian() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00667.java b/OWASP DATASET/BenchmarkTest00667.java new file mode 100644 index 0000000000000000000000000000000000000000..453034dd68830f99a063f1e81970a966d38c676f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00667.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00667") +public class BenchmarkTest00667 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00667"); + if (param == null) param = ""; + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + try { + int randNumber = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "SafeInga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt(int) - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt(int) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00668.java b/OWASP DATASET/BenchmarkTest00668.java new file mode 100644 index 0000000000000000000000000000000000000000..65ab63fa8500da6a83060ccc25a167de0475b3c1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00668.java @@ -0,0 +1,59 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00668") +public class BenchmarkTest00668 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00668"); + if (param == null) param = ""; + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String^,java.lang.Object) + request.getSession().putValue(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: 10340 saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00669.java b/OWASP DATASET/BenchmarkTest00669.java new file mode 100644 index 0000000000000000000000000000000000000000..c4d730261370617756084346937afc8f18388ee7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00669.java @@ -0,0 +1,64 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00669") +public class BenchmarkTest00669 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00669"); + if (param == null) param = ""; + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + // javax.servlet.http.HttpSession.putValue(java.lang.String^,java.lang.Object) + request.getSession().putValue(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: 10340 saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00670.java b/OWASP DATASET/BenchmarkTest00670.java new file mode 100644 index 0000000000000000000000000000000000000000..e28439864fefa0927a28cb08e9115d963ff976b8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00670.java @@ -0,0 +1,63 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00670") +public class BenchmarkTest00670 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00670"); + if (param == null) param = ""; + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz42704 = new StringBuilder(param); + bar = sbxyz42704.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + // javax.servlet.http.HttpSession.putValue(java.lang.String^,java.lang.Object) + request.getSession().putValue(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: 10340 saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00671.java b/OWASP DATASET/BenchmarkTest00671.java new file mode 100644 index 0000000000000000000000000000000000000000..5349125e3191b4af00f15b2d781b55a95f00a819 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00671.java @@ -0,0 +1,64 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00671") +public class BenchmarkTest00671 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00671"); + if (param == null) param = ""; + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + // javax.servlet.http.HttpSession.putValue(java.lang.String^,java.lang.Object) + request.getSession().putValue(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: 10340 saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00672.java b/OWASP DATASET/BenchmarkTest00672.java new file mode 100644 index 0000000000000000000000000000000000000000..efb70eb5e064fd7ccb853d4734814cda56954c96 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00672.java @@ -0,0 +1,71 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00672") +public class BenchmarkTest00672 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00672"); + if (param == null) param = ""; + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = connection.prepareCall(sql); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00673.java b/OWASP DATASET/BenchmarkTest00673.java new file mode 100644 index 0000000000000000000000000000000000000000..2e79baf50e7bdb1ee07c9d6d140ab0d99491b0d3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00673.java @@ -0,0 +1,71 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00673") +public class BenchmarkTest00673 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00673"); + if (param == null) param = ""; + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = connection.prepareStatement(sql); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00674.java b/OWASP DATASET/BenchmarkTest00674.java new file mode 100644 index 0000000000000000000000000000000000000000..3bcbdac1354adb3724f3a54fee7324e294eef5f6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00674.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00674") +public class BenchmarkTest00674 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00674"); + if (param == null) param = ""; + + // Chain a bunch of propagators in sequence + String a55926 = param; // assign + StringBuilder b55926 = new StringBuilder(a55926); // stick in stringbuilder + b55926.append(" SafeStuff"); // append some safe content + b55926.replace( + b55926.length() - "Chars".length(), + b55926.length(), + "Chars"); // replace some of the end content + java.util.HashMap map55926 = new java.util.HashMap(); + map55926.put("key55926", b55926.toString()); // put in a collection + String c55926 = (String) map55926.get("key55926"); // get it back out + String d55926 = c55926.substring(0, c55926.length() - 1); // extract most of it + String e55926 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d55926.getBytes()))); // B64 encode and decode it + String f55926 = e55926.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g55926 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g55926); // reflection + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00675.java b/OWASP DATASET/BenchmarkTest00675.java new file mode 100644 index 0000000000000000000000000000000000000000..54d39e3b384c626a1d0610aa9b6e38857a4eef24 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00675.java @@ -0,0 +1,72 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00675") +public class BenchmarkTest00675 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00675"); + if (param == null) param = ""; + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, new int[] {1, 2}); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00676.java b/OWASP DATASET/BenchmarkTest00676.java new file mode 100644 index 0000000000000000000000000000000000000000..251f9353b1b4bb504940af4de6eb92547e8de23a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00676.java @@ -0,0 +1,72 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00676") +public class BenchmarkTest00676 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00676"); + if (param == null) param = ""; + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, new String[] {"Column1", "Column2"}); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00677.java b/OWASP DATASET/BenchmarkTest00677.java new file mode 100644 index 0000000000000000000000000000000000000000..8517588a660c2cae7cfc5fe245dd5172acaf415f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00677.java @@ -0,0 +1,93 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00677") +public class BenchmarkTest00677 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00677"); + if (param == null) param = ""; + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.query( + sql, + new org.springframework.jdbc.core.RowMapper() { + @Override + public String mapRow(java.sql.ResultSet rs, int rowNum) + throws java.sql.SQLException { + try { + return rs.getString("USERNAME"); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper + .hideSQLErrors) { + return "Error processing query."; + } else throw e; + } + } + }); + response.getWriter().println("Your results are: "); + + for (String s : results) { + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(s) + "
"); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00678.java b/OWASP DATASET/BenchmarkTest00678.java new file mode 100644 index 0000000000000000000000000000000000000000..ef96153d62691bb1a067051ad0ee7e4e95174f24 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00678.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00678") +public class BenchmarkTest00678 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00678"); + if (param == null) param = ""; + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // Long results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForLong(sql); + Long results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Long.class); + response.getWriter().println("Your results are: " + String.valueOf(results)); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00679.java b/OWASP DATASET/BenchmarkTest00679.java new file mode 100644 index 0000000000000000000000000000000000000000..017e8358f553373abcc556003f56962d748daacc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00679.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00679") +public class BenchmarkTest00679 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00679"); + if (param == null) param = ""; + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + String sql = + "SELECT TOP 1 userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.Map results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForMap(sql); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(results.toString())); + // System.out.println(results.toString()); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00680.java b/OWASP DATASET/BenchmarkTest00680.java new file mode 100644 index 0000000000000000000000000000000000000000..3d6c32aab5d3272acbc4049ba755cfa0b285ae55 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00680.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00680") +public class BenchmarkTest00680 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00680"); + if (param == null) param = ""; + + String bar = "safe!"; + java.util.HashMap map33558 = new java.util.HashMap(); + map33558.put("keyA-33558", "a_Value"); // put some stuff in the collection + map33558.put("keyB-33558", param); // put it in a collection + map33558.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map33558.get("keyB-33558"); // get it back out + bar = (String) map33558.get("keyA-33558"); // get safe value back out + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00681.java b/OWASP DATASET/BenchmarkTest00681.java new file mode 100644 index 0000000000000000000000000000000000000000..49e5fa693e2406f6201169906c4bb99a9626cc28 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00681.java @@ -0,0 +1,64 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00681") +public class BenchmarkTest00681 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00681"); + if (param == null) param = ""; + + String bar = param; + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + java.sql.ResultSet rs = statement.executeQuery(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00682.java b/OWASP DATASET/BenchmarkTest00682.java new file mode 100644 index 0000000000000000000000000000000000000000..a67b602fb5b480904dc54f8e58a51e1016cb64d4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00682.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00682") +public class BenchmarkTest00682 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00682"); + if (param == null) param = ""; + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00683.java b/OWASP DATASET/BenchmarkTest00683.java new file mode 100644 index 0000000000000000000000000000000000000000..4dacc44a3b0f22f4e1c8151094766f4e520778c0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00683.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest00683") +public class BenchmarkTest00683 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest00683"); + if (param == null) param = ""; + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + org.w3c.dom.NodeList nodeList = + (org.w3c.dom.NodeList) + xp.compile(expression) + .evaluate(xmlDocument, javax.xml.xpath.XPathConstants.NODESET); + + response.getWriter().println("Your query results are:
"); + + for (int i = 0; i < nodeList.getLength(); i++) { + org.w3c.dom.Element value = (org.w3c.dom.Element) nodeList.item(i); + response.getWriter().println(value.getTextContent() + "
"); + } + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00684.java b/OWASP DATASET/BenchmarkTest00684.java new file mode 100644 index 0000000000000000000000000000000000000000..20713c9a1171cd7b15dfb04ee53b7699f864dab0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00684.java @@ -0,0 +1,150 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00684") +public class BenchmarkTest00684 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00684"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "DES/CBC/PKCS5PADDING", java.security.Security.getProvider("SunJCE")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00685.java b/OWASP DATASET/BenchmarkTest00685.java new file mode 100644 index 0000000000000000000000000000000000000000..b2785e53b3263df5cc53ba2e2a1fe88d2ce41f57 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00685.java @@ -0,0 +1,154 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00685") +public class BenchmarkTest00685 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00685"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz40853 = new StringBuilder(param); + bar = sbxyz40853.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "DES/CBC/PKCS5PADDING", java.security.Security.getProvider("SunJCE")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00686.java b/OWASP DATASET/BenchmarkTest00686.java new file mode 100644 index 0000000000000000000000000000000000000000..08f515ad1e67d5472b8fb0ef8cfc7f6a9c550514 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00686.java @@ -0,0 +1,158 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00686") +public class BenchmarkTest00686 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00686"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00687.java b/OWASP DATASET/BenchmarkTest00687.java new file mode 100644 index 0000000000000000000000000000000000000000..827c52e27950cf526621db0d1e9e826938821a88 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00687.java @@ -0,0 +1,156 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00687") +public class BenchmarkTest00687 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00687"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00688.java b/OWASP DATASET/BenchmarkTest00688.java new file mode 100644 index 0000000000000000000000000000000000000000..458c53a0dda52b54a71d2dcd0efdd0461c8e674e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00688.java @@ -0,0 +1,161 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00688") +public class BenchmarkTest00688 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00688"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00689.java b/OWASP DATASET/BenchmarkTest00689.java new file mode 100644 index 0000000000000000000000000000000000000000..445de521f1f88e7d6765a52c9e768d0ff81a8f6b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00689.java @@ -0,0 +1,131 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00689") +public class BenchmarkTest00689 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00689"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + // Chain a bunch of propagators in sequence + String a98281 = param; // assign + StringBuilder b98281 = new StringBuilder(a98281); // stick in stringbuilder + b98281.append(" SafeStuff"); // append some safe content + b98281.replace( + b98281.length() - "Chars".length(), + b98281.length(), + "Chars"); // replace some of the end content + java.util.HashMap map98281 = new java.util.HashMap(); + map98281.put("key98281", b98281.toString()); // put in a collection + String c98281 = (String) map98281.get("key98281"); // get it back out + String d98281 = c98281.substring(0, c98281.length() - 1); // extract most of it + String e98281 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d98281.getBytes()))); // B64 encode and decode it + String f98281 = e98281.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g98281 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g98281); // reflection + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = org.owasp.benchmark.helpers.Utils.getCipher(); + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00690.java b/OWASP DATASET/BenchmarkTest00690.java new file mode 100644 index 0000000000000000000000000000000000000000..15e29b4595b48767d2f9b853ca7219225e48394d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00690.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00690") +public class BenchmarkTest00690 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00690"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = org.owasp.benchmark.helpers.Utils.getCipher(); + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00691.java b/OWASP DATASET/BenchmarkTest00691.java new file mode 100644 index 0000000000000000000000000000000000000000..56dce170a14f0572de11e6d52185d3c2b06bb755 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00691.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-00/BenchmarkTest00691") +public class BenchmarkTest00691 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00691"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00692.java b/OWASP DATASET/BenchmarkTest00692.java new file mode 100644 index 0000000000000000000000000000000000000000..6bb158b3c87eaca2e4b499f4f5678a1a8ed4e4a6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00692.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest00692") +public class BenchmarkTest00692 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00692"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00693.java b/OWASP DATASET/BenchmarkTest00693.java new file mode 100644 index 0000000000000000000000000000000000000000..835ead317c3ed9288a5285aa29b50ccc4c87e34e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00693.java @@ -0,0 +1,123 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest00693") +public class BenchmarkTest00693 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00693"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00694.java b/OWASP DATASET/BenchmarkTest00694.java new file mode 100644 index 0000000000000000000000000000000000000000..92eeeb0cf2dca8548ccecc95ec153b2077dd52e2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00694.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest00694") +public class BenchmarkTest00694 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00694"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = param; + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + javax.naming.directory.DirContext ctx = ads.getDirContext(); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person)(uid=" + bar + "))"; + // System.out.println("Filter " + filter); + boolean found = false; + javax.naming.NamingEnumeration results = + ctx.search(base, filter, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00695.java b/OWASP DATASET/BenchmarkTest00695.java new file mode 100644 index 0000000000000000000000000000000000000000..02b814e3d5136ab88f1cb2f2c7552b39f95d8301 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00695.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest00695") +public class BenchmarkTest00695 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00695"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = "safe!"; + java.util.HashMap map9400 = new java.util.HashMap(); + map9400.put("keyA-9400", "a-Value"); // put some stuff in the collection + map9400.put("keyB-9400", param); // put it in a collection + map9400.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map9400.get("keyB-9400"); // get it back out + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + javax.naming.directory.DirContext ctx = ads.getDirContext(); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person)(uid=" + bar + "))"; + // System.out.println("Filter " + filter); + boolean found = false; + javax.naming.NamingEnumeration results = + ctx.search(base, filter, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00696.java b/OWASP DATASET/BenchmarkTest00696.java new file mode 100644 index 0000000000000000000000000000000000000000..c60f6bdf1d4dbae1df9b4eae95e5f0f4382c9ff7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00696.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00696") +public class BenchmarkTest00696 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00696"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + java.io.File fileTarget = + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR, bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00697.java b/OWASP DATASET/BenchmarkTest00697.java new file mode 100644 index 0000000000000000000000000000000000000000..806a59aab96f315680b44d10a39d7fb83a1f3404 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00697.java @@ -0,0 +1,73 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00697") +public class BenchmarkTest00697 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00697"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + java.io.File fileTarget = new java.io.File(bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00698.java b/OWASP DATASET/BenchmarkTest00698.java new file mode 100644 index 0000000000000000000000000000000000000000..4fb641881f620b495337155f5620c571965e7c67 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00698.java @@ -0,0 +1,68 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00698") +public class BenchmarkTest00698 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00698"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + java.io.File fileTarget = new java.io.File(bar, "/Test.txt"); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00699.java b/OWASP DATASET/BenchmarkTest00699.java new file mode 100644 index 0000000000000000000000000000000000000000..57a88dac4f79e6532f4b518d77511aeaca5f3ee5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00699.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00699") +public class BenchmarkTest00699 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00699"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + java.io.File fileTarget = new java.io.File(bar, "/Test.txt"); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00700.java b/OWASP DATASET/BenchmarkTest00700.java new file mode 100644 index 0000000000000000000000000000000000000000..9980880cb52825294550a745c0ebcd4e7d9b521b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00700.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00700") +public class BenchmarkTest00700 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00700"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName)); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00701.java b/OWASP DATASET/BenchmarkTest00701.java new file mode 100644 index 0000000000000000000000000000000000000000..872835ece40076e969c63bcea9489816830c2c2e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00701.java @@ -0,0 +1,123 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest00701") +public class BenchmarkTest00701 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00701"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + // Chain a bunch of propagators in sequence + String a85232 = param; // assign + StringBuilder b85232 = new StringBuilder(a85232); // stick in stringbuilder + b85232.append(" SafeStuff"); // append some safe content + b85232.replace( + b85232.length() - "Chars".length(), + b85232.length(), + "Chars"); // replace some of the end content + java.util.HashMap map85232 = new java.util.HashMap(); + map85232.put("key85232", b85232.toString()); // put in a collection + String c85232 = (String) map85232.get("key85232"); // get it back out + String d85232 = c85232.substring(0, c85232.length() - 1); // extract most of it + String e85232 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d85232.getBytes()))); // B64 encode and decode it + String f85232 = e85232.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g85232 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g85232); // reflection + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person)(uid=" + bar + "))"; + + javax.naming.directory.DirContext ctx = ads.getDirContext(); + javax.naming.directory.InitialDirContext idc = + (javax.naming.directory.InitialDirContext) ctx; + boolean found = false; + javax.naming.NamingEnumeration results = + idc.search(base, filter, sc); + + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00702.java b/OWASP DATASET/BenchmarkTest00702.java new file mode 100644 index 0000000000000000000000000000000000000000..364ee86a3902ccbd954247eae9a4a3c616e604da --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00702.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00702") +public class BenchmarkTest00702 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00702"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + double value = java.lang.Math.random(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Doug"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + response.getWriter().println("Weak Randomness Test java.lang.Math.random() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00703.java b/OWASP DATASET/BenchmarkTest00703.java new file mode 100644 index 0000000000000000000000000000000000000000..b06e6733459c7902f4b29aa908110bcb3c997397 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00703.java @@ -0,0 +1,122 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00703") +public class BenchmarkTest00703 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00703"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("SHA1", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00704.java b/OWASP DATASET/BenchmarkTest00704.java new file mode 100644 index 0000000000000000000000000000000000000000..e0518469eda2bced4c0c87461ed8bde21f6c9e49 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00704.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00704") +public class BenchmarkTest00704 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00704"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("SHA1", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00705.java b/OWASP DATASET/BenchmarkTest00705.java new file mode 100644 index 0000000000000000000000000000000000000000..0061edc6d5d593490d9f11bf0978028012c29f0d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00705.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00705") +public class BenchmarkTest00705 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00705"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = "safe!"; + java.util.HashMap map71551 = new java.util.HashMap(); + map71551.put("keyA-71551", "a_Value"); // put some stuff in the collection + map71551.put("keyB-71551", param); // put it in a collection + map71551.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map71551.get("keyB-71551"); // get it back out + bar = (String) map71551.get("keyA-71551"); // get safe value back out + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00706.java b/OWASP DATASET/BenchmarkTest00706.java new file mode 100644 index 0000000000000000000000000000000000000000..7bf740d404a18d77144d10a4e402ab9cb47deb42 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00706.java @@ -0,0 +1,105 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00706") +public class BenchmarkTest00706 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00706"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + try { + java.security.MessageDigest md = + java.security.MessageDigest.getInstance("SHA-512", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00707.java b/OWASP DATASET/BenchmarkTest00707.java new file mode 100644 index 0000000000000000000000000000000000000000..c525f885f8fbc7b84d903088ce82b73cd4f91832 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00707.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00707") +public class BenchmarkTest00707 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00707"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + try { + java.security.MessageDigest md = + java.security.MessageDigest.getInstance("SHA-512", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00708.java b/OWASP DATASET/BenchmarkTest00708.java new file mode 100644 index 0000000000000000000000000000000000000000..edb90ae601207e79b5decf172d845d9194e655a8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00708.java @@ -0,0 +1,101 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00708") +public class BenchmarkTest00708 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00708"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00709.java b/OWASP DATASET/BenchmarkTest00709.java new file mode 100644 index 0000000000000000000000000000000000000000..58409ab8e5046f26be16f89f18ef9fa9937564df --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00709.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00709") +public class BenchmarkTest00709 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00709"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-256"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00710.java b/OWASP DATASET/BenchmarkTest00710.java new file mode 100644 index 0000000000000000000000000000000000000000..bfe93a0bc6bfd33f54032510918bb29628090887 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00710.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00710") +public class BenchmarkTest00710 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00710"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00711.java b/OWASP DATASET/BenchmarkTest00711.java new file mode 100644 index 0000000000000000000000000000000000000000..006ca7adaaab63b70a4c61775d92535ed24718e2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00711.java @@ -0,0 +1,67 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00711") +public class BenchmarkTest00711 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00711"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + java.io.PrintWriter out = response.getWriter(); + out.write("\n\n\n

"); + out.format(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + out.write("\n

\n\n"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00712.java b/OWASP DATASET/BenchmarkTest00712.java new file mode 100644 index 0000000000000000000000000000000000000000..dc390fc2d13785858f7ed0901fc68e2bd199d554 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00712.java @@ -0,0 +1,62 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00712") +public class BenchmarkTest00712 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00712"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + java.io.PrintWriter out = response.getWriter(); + out.write("\n\n\n

"); + out.format(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + out.write("\n

\n\n"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00713.java b/OWASP DATASET/BenchmarkTest00713.java new file mode 100644 index 0000000000000000000000000000000000000000..179844423f079e0d511c43875749e58bac0a40db --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00713.java @@ -0,0 +1,54 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00713") +public class BenchmarkTest00713 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00713"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(java.util.Locale.US, bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00714.java b/OWASP DATASET/BenchmarkTest00714.java new file mode 100644 index 0000000000000000000000000000000000000000..025e9ecadfeb20ae338dab393c719b996dcd7854 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00714.java @@ -0,0 +1,54 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00714") +public class BenchmarkTest00714 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00714"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().format("Formatted like: %1$s and %2$s.", obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00715.java b/OWASP DATASET/BenchmarkTest00715.java new file mode 100644 index 0000000000000000000000000000000000000000..b85d505869f562aa3c5c84ed90765853d1c18f3e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00715.java @@ -0,0 +1,54 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00715") +public class BenchmarkTest00715 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00715"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00716.java b/OWASP DATASET/BenchmarkTest00716.java new file mode 100644 index 0000000000000000000000000000000000000000..b7646759c6c5422af4d78b2f364d9a545c3af267 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00716.java @@ -0,0 +1,54 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00716") +public class BenchmarkTest00716 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00716"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00717.java b/OWASP DATASET/BenchmarkTest00717.java new file mode 100644 index 0000000000000000000000000000000000000000..4f5b43b440e38eabaaa173853d59a49065757d5d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00717.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00717") +public class BenchmarkTest00717 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00717"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + // Chain a bunch of propagators in sequence + String a59129 = param; // assign + StringBuilder b59129 = new StringBuilder(a59129); // stick in stringbuilder + b59129.append(" SafeStuff"); // append some safe content + b59129.replace( + b59129.length() - "Chars".length(), + b59129.length(), + "Chars"); // replace some of the end content + java.util.HashMap map59129 = new java.util.HashMap(); + map59129.put("key59129", b59129.toString()); // put in a collection + String c59129 = (String) map59129.get("key59129"); // get it back out + String d59129 = c59129.substring(0, c59129.length() - 1); // extract most of it + String e59129 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d59129.getBytes()))); // B64 encode and decode it + String f59129 = e59129.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g59129 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g59129); // reflection + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00718.java b/OWASP DATASET/BenchmarkTest00718.java new file mode 100644 index 0000000000000000000000000000000000000000..23c73256066f5b17bfbc21956365cf62a5866105 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00718.java @@ -0,0 +1,54 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00718") +public class BenchmarkTest00718 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00718"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00719.java b/OWASP DATASET/BenchmarkTest00719.java new file mode 100644 index 0000000000000000000000000000000000000000..8692ecbe1e8d1654029ac753af49952afa9f19dd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00719.java @@ -0,0 +1,56 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00719") +public class BenchmarkTest00719 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00719"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(java.util.Locale.US, bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00720.java b/OWASP DATASET/BenchmarkTest00720.java new file mode 100644 index 0000000000000000000000000000000000000000..b5b11fe8d25c9726f47355dab71dccce7fc397bd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00720.java @@ -0,0 +1,73 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00720") +public class BenchmarkTest00720 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00720"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(java.util.Locale.US, bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00721.java b/OWASP DATASET/BenchmarkTest00721.java new file mode 100644 index 0000000000000000000000000000000000000000..4feb307da11745e4584a8a24d1eea97e4a7554e2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00721.java @@ -0,0 +1,64 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00721") +public class BenchmarkTest00721 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00721"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {bar, "b"}; + response.getWriter().printf("Formatted like: %1$s and %2$s.", obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00722.java b/OWASP DATASET/BenchmarkTest00722.java new file mode 100644 index 0000000000000000000000000000000000000000..a587010ac0eb7ee043d679c639c8e6bb92da335b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00722.java @@ -0,0 +1,60 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00722") +public class BenchmarkTest00722 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00722"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = "safe!"; + java.util.HashMap map49442 = new java.util.HashMap(); + map49442.put("keyA-49442", "a_Value"); // put some stuff in the collection + map49442.put("keyB-49442", param); // put it in a collection + map49442.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map49442.get("keyB-49442"); // get it back out + bar = (String) map49442.get("keyA-49442"); // get safe value back out + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00723.java b/OWASP DATASET/BenchmarkTest00723.java new file mode 100644 index 0000000000000000000000000000000000000000..9d0179e3c3766a33f1fee6c46b9c917eb0f9c043 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00723.java @@ -0,0 +1,59 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00723") +public class BenchmarkTest00723 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00723"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00724.java b/OWASP DATASET/BenchmarkTest00724.java new file mode 100644 index 0000000000000000000000000000000000000000..0ead59464d167d94b4a73cb4a102536b42d63f1c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00724.java @@ -0,0 +1,72 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00724") +public class BenchmarkTest00724 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00724"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00725.java b/OWASP DATASET/BenchmarkTest00725.java new file mode 100644 index 0000000000000000000000000000000000000000..2a128b742dbafcb0da0afbcdebcef973784e70d0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00725.java @@ -0,0 +1,73 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00725") +public class BenchmarkTest00725 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00725"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + // Chain a bunch of propagators in sequence + String a49441 = param; // assign + StringBuilder b49441 = new StringBuilder(a49441); // stick in stringbuilder + b49441.append(" SafeStuff"); // append some safe content + b49441.replace( + b49441.length() - "Chars".length(), + b49441.length(), + "Chars"); // replace some of the end content + java.util.HashMap map49441 = new java.util.HashMap(); + map49441.put("key49441", b49441.toString()); // put in a collection + String c49441 = (String) map49441.get("key49441"); // get it back out + String d49441 = c49441.substring(0, c49441.length() - 1); // extract most of it + String e49441 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d49441.getBytes()))); // B64 encode and decode it + String f49441 = e49441.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f49441); // reflection + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00726.java b/OWASP DATASET/BenchmarkTest00726.java new file mode 100644 index 0000000000000000000000000000000000000000..00f7c7af9a5f6ad7e1c44ce1ee670ad4c2be4d72 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00726.java @@ -0,0 +1,53 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00726") +public class BenchmarkTest00726 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00726"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00727.java b/OWASP DATASET/BenchmarkTest00727.java new file mode 100644 index 0000000000000000000000000000000000000000..c8a7f358f11db7a854905cc59c584c4e72c8ca91 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00727.java @@ -0,0 +1,56 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00727") +public class BenchmarkTest00727 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00727"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00728.java b/OWASP DATASET/BenchmarkTest00728.java new file mode 100644 index 0000000000000000000000000000000000000000..d6df56ca991700e016e5eb94592c46ea843f8482 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00728.java @@ -0,0 +1,58 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00728") +public class BenchmarkTest00728 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00728"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00729.java b/OWASP DATASET/BenchmarkTest00729.java new file mode 100644 index 0000000000000000000000000000000000000000..3f299aa023a8f51a7318fb22f6d7dd8e1c58183a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00729.java @@ -0,0 +1,55 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00729") +public class BenchmarkTest00729 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00729"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar.toCharArray()); + } +} diff --git a/OWASP DATASET/BenchmarkTest00730.java b/OWASP DATASET/BenchmarkTest00730.java new file mode 100644 index 0000000000000000000000000000000000000000..87eba9b95436e8d656b1897c58a3dcabe8061dde --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00730.java @@ -0,0 +1,59 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00730") +public class BenchmarkTest00730 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00730"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = "safe!"; + java.util.HashMap map29173 = new java.util.HashMap(); + map29173.put("keyA-29173", "a_Value"); // put some stuff in the collection + map29173.put("keyB-29173", param); // put it in a collection + map29173.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map29173.get("keyB-29173"); // get it back out + bar = (String) map29173.get("keyA-29173"); // get safe value back out + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar.toCharArray()); + } +} diff --git a/OWASP DATASET/BenchmarkTest00731.java b/OWASP DATASET/BenchmarkTest00731.java new file mode 100644 index 0000000000000000000000000000000000000000..045b4f565f378ae7d661bdf77d074e2d6c66ece6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00731.java @@ -0,0 +1,73 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00731") +public class BenchmarkTest00731 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00731"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = param; + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00732.java b/OWASP DATASET/BenchmarkTest00732.java new file mode 100644 index 0000000000000000000000000000000000000000..63e4278a13a58da1c2009488973e0c4bba1539d0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00732.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00732") +public class BenchmarkTest00732 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00732"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = "safe!"; + java.util.HashMap map99333 = new java.util.HashMap(); + map99333.put("keyA-99333", "a_Value"); // put some stuff in the collection + map99333.put("keyB-99333", param); // put it in a collection + map99333.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map99333.get("keyB-99333"); // get it back out + bar = (String) map99333.get("keyA-99333"); // get safe value back out + + String a1 = ""; + String a2 = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + } else { + a1 = "sh"; + a2 = "-c"; + } + String[] args = {a1, a2, "echo " + bar}; + + ProcessBuilder pb = new ProcessBuilder(args); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.lang.String[]) Test Case"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00733.java b/OWASP DATASET/BenchmarkTest00733.java new file mode 100644 index 0000000000000000000000000000000000000000..d797ca21c2f3f8992d3496c84ccc9415350c0a8d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00733.java @@ -0,0 +1,100 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00733") +public class BenchmarkTest00733 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00733"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + StringBuilder sbxyz15959 = new StringBuilder(param); + String bar = sbxyz15959.append("_SafeStuff").toString(); + + double value = new java.util.Random().nextDouble(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Donna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextDouble() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00734.java b/OWASP DATASET/BenchmarkTest00734.java new file mode 100644 index 0000000000000000000000000000000000000000..45787c8952c25ff6b3c0506a3b4e3e112889388a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00734.java @@ -0,0 +1,118 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00734") +public class BenchmarkTest00734 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00734"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + double stuff = new java.util.Random().nextGaussian(); + String rememberMeKey = Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "Gayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter() + .println("Weak Randomness Test java.util.Random.nextGaussian() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00735.java b/OWASP DATASET/BenchmarkTest00735.java new file mode 100644 index 0000000000000000000000000000000000000000..9b9aa1463be58deb1ab5b9e7fd908045440a26cf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00735.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00735") +public class BenchmarkTest00735 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00735"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00736.java b/OWASP DATASET/BenchmarkTest00736.java new file mode 100644 index 0000000000000000000000000000000000000000..69b7d39d5cd948f8fb73c764d64bc9084fb78365 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00736.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest00736") +public class BenchmarkTest00736 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00736"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00737.java b/OWASP DATASET/BenchmarkTest00737.java new file mode 100644 index 0000000000000000000000000000000000000000..06b8d07a4bdd632ce8bf6a2a2ad20791644cc321 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00737.java @@ -0,0 +1,73 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00737") +public class BenchmarkTest00737 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00737"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + // Chain a bunch of propagators in sequence + String a57334 = param; // assign + StringBuilder b57334 = new StringBuilder(a57334); // stick in stringbuilder + b57334.append(" SafeStuff"); // append some safe content + b57334.replace( + b57334.length() - "Chars".length(), + b57334.length(), + "Chars"); // replace some of the end content + java.util.HashMap map57334 = new java.util.HashMap(); + map57334.put("key57334", b57334.toString()); // put in a collection + String c57334 = (String) map57334.get("key57334"); // get it back out + String d57334 = c57334.substring(0, c57334.length() - 1); // extract most of it + String e57334 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d57334.getBytes()))); // B64 encode and decode it + String f57334 = e57334.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f57334); // reflection + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write("Parameter value: " + bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00738.java b/OWASP DATASET/BenchmarkTest00738.java new file mode 100644 index 0000000000000000000000000000000000000000..71fecd2be284c3180d4be620811d066148c83d78 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00738.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00738") +public class BenchmarkTest00738 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00738"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00739.java b/OWASP DATASET/BenchmarkTest00739.java new file mode 100644 index 0000000000000000000000000000000000000000..86107cf26d4a60bdf4bdac7e4a44b2be319b4376 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00739.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00739") +public class BenchmarkTest00739 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00739"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00740.java b/OWASP DATASET/BenchmarkTest00740.java new file mode 100644 index 0000000000000000000000000000000000000000..6c39f06a0cb222bc7fcd6ccfc01e04af4efe2c6c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00740.java @@ -0,0 +1,73 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00740") +public class BenchmarkTest00740 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00740"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = "safe!"; + java.util.HashMap map87432 = new java.util.HashMap(); + map87432.put("keyA-87432", "a-Value"); // put some stuff in the collection + map87432.put("keyB-87432", param); // put it in a collection + map87432.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map87432.get("keyB-87432"); // get it back out + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00741.java b/OWASP DATASET/BenchmarkTest00741.java new file mode 100644 index 0000000000000000000000000000000000000000..7ca68bdfc504383f0879c9f7e314c2e1dfd23b22 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00741.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00741") +public class BenchmarkTest00741 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00741"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00742.java b/OWASP DATASET/BenchmarkTest00742.java new file mode 100644 index 0000000000000000000000000000000000000000..1ceed6d068ef79dce10b6f8d266535e1e1605b1b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00742.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00742") +public class BenchmarkTest00742 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00742"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = "safe!"; + java.util.HashMap map62435 = new java.util.HashMap(); + map62435.put("keyA-62435", "a_Value"); // put some stuff in the collection + map62435.put("keyB-62435", param); // put it in a collection + map62435.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map62435.get("keyB-62435"); // get it back out + bar = (String) map62435.get("keyA-62435"); // get safe value back out + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = + r.exec(cmd + bar, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00743.java b/OWASP DATASET/BenchmarkTest00743.java new file mode 100644 index 0000000000000000000000000000000000000000..b5f7b09dc7d471100e0ee155805923655561b09f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00743.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00743") +public class BenchmarkTest00743 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00743"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + try { + Process p = r.exec(cmd, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00744.java b/OWASP DATASET/BenchmarkTest00744.java new file mode 100644 index 0000000000000000000000000000000000000000..ef219a7802a6f679f6d6d7efca0f716058ae109f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00744.java @@ -0,0 +1,123 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00744") +public class BenchmarkTest00744 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00744"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00745.java b/OWASP DATASET/BenchmarkTest00745.java new file mode 100644 index 0000000000000000000000000000000000000000..734c337ab6f59b0f077d9b6a586a02aec6819da1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00745.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00745") +public class BenchmarkTest00745 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00745"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00746.java b/OWASP DATASET/BenchmarkTest00746.java new file mode 100644 index 0000000000000000000000000000000000000000..03577a6befe0fca20de24219aeabb18bf6922da3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00746.java @@ -0,0 +1,132 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00746") +public class BenchmarkTest00746 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00746"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00747.java b/OWASP DATASET/BenchmarkTest00747.java new file mode 100644 index 0000000000000000000000000000000000000000..5a47fcd1dd78f26e0f433fae2badb91867a093e7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00747.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00747") +public class BenchmarkTest00747 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00747"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + getNextNumber(numGen, randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeBystander"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } + + void getNextNumber(java.util.Random generator, byte[] barray) { + generator.nextBytes(barray); + } +} diff --git a/OWASP DATASET/BenchmarkTest00748.java b/OWASP DATASET/BenchmarkTest00748.java new file mode 100644 index 0000000000000000000000000000000000000000..5607de3123c27bc462c82deaadbc3ec315541a4f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00748.java @@ -0,0 +1,137 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00748") +public class BenchmarkTest00748 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00748"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + // Chain a bunch of propagators in sequence + String a43085 = param; // assign + StringBuilder b43085 = new StringBuilder(a43085); // stick in stringbuilder + b43085.append(" SafeStuff"); // append some safe content + b43085.replace( + b43085.length() - "Chars".length(), + b43085.length(), + "Chars"); // replace some of the end content + java.util.HashMap map43085 = new java.util.HashMap(); + map43085.put("key43085", b43085.toString()); // put in a collection + String c43085 = (String) map43085.get("key43085"); // get it back out + String d43085 = c43085.substring(0, c43085.length() - 1); // extract most of it + String e43085 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d43085.getBytes()))); // B64 encode and decode it + String f43085 = e43085.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g43085 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g43085); // reflection + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + getNextNumber(numGen, randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeBystander"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } + + void getNextNumber(java.util.Random generator, byte[] barray) { + generator.nextBytes(barray); + } +} diff --git a/OWASP DATASET/BenchmarkTest00749.java b/OWASP DATASET/BenchmarkTest00749.java new file mode 100644 index 0000000000000000000000000000000000000000..5c05aa6216baad1ae4e0eec11f24a8a932ea2cab --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00749.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00749") +public class BenchmarkTest00749 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00749"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + StringBuilder sbxyz94097 = new StringBuilder(param); + String bar = sbxyz94097.append("_SafeStuff").toString(); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + double rand = getNextNumber(numGen); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonatella"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } + + double getNextNumber(java.util.Random generator) { + return generator.nextDouble(); + } +} diff --git a/OWASP DATASET/BenchmarkTest00750.java b/OWASP DATASET/BenchmarkTest00750.java new file mode 100644 index 0000000000000000000000000000000000000000..7de857a34f1b0603a986cef67ff592bca7720e84 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00750.java @@ -0,0 +1,111 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00750") +public class BenchmarkTest00750 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00750"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz18731 = new StringBuilder(param); + bar = sbxyz18731.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00751.java b/OWASP DATASET/BenchmarkTest00751.java new file mode 100644 index 0000000000000000000000000000000000000000..49db4aa7e3dda50be21cdeecd8311e67c918d94b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00751.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00751") +public class BenchmarkTest00751 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00751"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00752.java b/OWASP DATASET/BenchmarkTest00752.java new file mode 100644 index 0000000000000000000000000000000000000000..ca5327ef658d5be85562222fc24c2668c37a8988 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00752.java @@ -0,0 +1,123 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00752") +public class BenchmarkTest00752 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00752"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + try { + int r = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "SafeIngrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00753.java b/OWASP DATASET/BenchmarkTest00753.java new file mode 100644 index 0000000000000000000000000000000000000000..a68df1e18c166ac06bd7f350259c56c9efcebfd8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00753.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00753") +public class BenchmarkTest00753 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00753"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + try { + long l = java.security.SecureRandom.getInstance("SHA1PRNG").nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "SafeLogan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextLong() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextLong() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00754.java b/OWASP DATASET/BenchmarkTest00754.java new file mode 100644 index 0000000000000000000000000000000000000000..e4b1205732cfab4836be47901612af812f8037b2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00754.java @@ -0,0 +1,64 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00754") +public class BenchmarkTest00754 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00754"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = "safe!"; + java.util.HashMap map6425 = new java.util.HashMap(); + map6425.put("keyA-6425", "a-Value"); // put some stuff in the collection + map6425.put("keyB-6425", param); // put it in a collection + map6425.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map6425.get("keyB-6425"); // get it back out + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00755.java b/OWASP DATASET/BenchmarkTest00755.java new file mode 100644 index 0000000000000000000000000000000000000000..8ed608b6c2da4c8f52de58fbcd65ff444c4400dd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00755.java @@ -0,0 +1,64 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00755") +public class BenchmarkTest00755 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00755"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00756.java b/OWASP DATASET/BenchmarkTest00756.java new file mode 100644 index 0000000000000000000000000000000000000000..8c0dbb8f706ddd816e1df55c4e351b4cc1395349 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00756.java @@ -0,0 +1,59 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00756") +public class BenchmarkTest00756 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00756"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00757.java b/OWASP DATASET/BenchmarkTest00757.java new file mode 100644 index 0000000000000000000000000000000000000000..1ac2f8cd2741a0aeb3eb06da551b1031c4bb6517 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00757.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00757") +public class BenchmarkTest00757 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00757"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String^,java.lang.Object) + request.getSession().setAttribute(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: '10340' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00758.java b/OWASP DATASET/BenchmarkTest00758.java new file mode 100644 index 0000000000000000000000000000000000000000..1f089fa7107779221e2a85c9704aa89580fadac0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00758.java @@ -0,0 +1,69 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00758") +public class BenchmarkTest00758 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00758"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00759.java b/OWASP DATASET/BenchmarkTest00759.java new file mode 100644 index 0000000000000000000000000000000000000000..07a650eafd0cbfd2f9f7f2a56637fdd264292ba6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00759.java @@ -0,0 +1,62 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00759") +public class BenchmarkTest00759 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00759"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00760.java b/OWASP DATASET/BenchmarkTest00760.java new file mode 100644 index 0000000000000000000000000000000000000000..bd35513af149a4e932c052279105247c9565d425 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00760.java @@ -0,0 +1,71 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00760") +public class BenchmarkTest00760 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00760"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = "safe!"; + java.util.HashMap map18915 = new java.util.HashMap(); + map18915.put("keyA-18915", "a-Value"); // put some stuff in the collection + map18915.put("keyB-18915", param); // put it in a collection + map18915.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map18915.get("keyB-18915"); // get it back out + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = connection.prepareCall(sql); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00761.java b/OWASP DATASET/BenchmarkTest00761.java new file mode 100644 index 0000000000000000000000000000000000000000..c9be8a029157a03c3fa9fe8fa1a41eb6e0fe52f0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00761.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00761") +public class BenchmarkTest00761 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00761"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = connection.prepareCall(sql); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00762.java b/OWASP DATASET/BenchmarkTest00762.java new file mode 100644 index 0000000000000000000000000000000000000000..74259017a83390ff84b70a47a65da0ab941442e6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00762.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00762") +public class BenchmarkTest00762 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00762"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00763.java b/OWASP DATASET/BenchmarkTest00763.java new file mode 100644 index 0000000000000000000000000000000000000000..c4157404068c90668ede04e7f411851112f9137a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00763.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00763") +public class BenchmarkTest00763 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00763"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, new int[] {1, 2}); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00764.java b/OWASP DATASET/BenchmarkTest00764.java new file mode 100644 index 0000000000000000000000000000000000000000..3e16ab6892e8099c49dad7000e0edf2f4432f83f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00764.java @@ -0,0 +1,69 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00764") +public class BenchmarkTest00764 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00764"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = param; + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // Long results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForLong(sql); + Long results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Long.class); + response.getWriter().println("Your results are: " + String.valueOf(results)); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00765.java b/OWASP DATASET/BenchmarkTest00765.java new file mode 100644 index 0000000000000000000000000000000000000000..3144ac8a20d3b8e26631703185b7a238b5905347 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00765.java @@ -0,0 +1,71 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00765") +public class BenchmarkTest00765 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00765"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // Long results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForLong(sql); + Long results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Long.class); + response.getWriter().println("Your results are: " + String.valueOf(results)); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00766.java b/OWASP DATASET/BenchmarkTest00766.java new file mode 100644 index 0000000000000000000000000000000000000000..0f190ad38c065795e32de35e84cc89e5ac278d17 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00766.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00766") +public class BenchmarkTest00766 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00766"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // Long results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForLong(sql); + Long results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Long.class); + response.getWriter().println("Your results are: " + String.valueOf(results)); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00767.java b/OWASP DATASET/BenchmarkTest00767.java new file mode 100644 index 0000000000000000000000000000000000000000..a8189188fd554b0c7f6930d689b5deef2df44a79 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00767.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00767") +public class BenchmarkTest00767 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00767"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // Long results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForLong(sql); + Long results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Long.class); + response.getWriter().println("Your results are: " + String.valueOf(results)); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00768.java b/OWASP DATASET/BenchmarkTest00768.java new file mode 100644 index 0000000000000000000000000000000000000000..b0acb740bec648cff707afa37f317fda056121c4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00768.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00768") +public class BenchmarkTest00768 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00768"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + String sql = + "SELECT TOP 1 userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.Map results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForMap(sql); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(results.toString())); + // System.out.println(results.toString()); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00769.java b/OWASP DATASET/BenchmarkTest00769.java new file mode 100644 index 0000000000000000000000000000000000000000..ca2e9bbfad92a11aeb0af2b31097c3a2cad667a6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00769.java @@ -0,0 +1,71 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00769") +public class BenchmarkTest00769 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00769"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = "safe!"; + java.util.HashMap map29572 = new java.util.HashMap(); + map29572.put("keyA-29572", "a-Value"); // put some stuff in the collection + map29572.put("keyB-29572", param); // put it in a collection + map29572.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map29572.get("keyB-29572"); // get it back out + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00770.java b/OWASP DATASET/BenchmarkTest00770.java new file mode 100644 index 0000000000000000000000000000000000000000..8a01f043689da04d55d88b9f31f3fd813b856300 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00770.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00770") +public class BenchmarkTest00770 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00770"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.addBatch(sql); + int[] counts = statement.executeBatch(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(sql, counts, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00771.java b/OWASP DATASET/BenchmarkTest00771.java new file mode 100644 index 0000000000000000000000000000000000000000..fd8d7c3f4253f9927abef63c7c669cc9dfa5ba1f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00771.java @@ -0,0 +1,69 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00771") +public class BenchmarkTest00771 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00771"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = "safe!"; + java.util.HashMap map49960 = new java.util.HashMap(); + map49960.put("keyA-49960", "a-Value"); // put some stuff in the collection + map49960.put("keyB-49960", param); // put it in a collection + map49960.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map49960.get("keyB-49960"); // get it back out + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00772.java b/OWASP DATASET/BenchmarkTest00772.java new file mode 100644 index 0000000000000000000000000000000000000000..e119ad0711dfcba685eb13cf6b12ce11211249fc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00772.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00772") +public class BenchmarkTest00772 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00772"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00773.java b/OWASP DATASET/BenchmarkTest00773.java new file mode 100644 index 0000000000000000000000000000000000000000..0968a1c07305c5da98a6a541415f05350ce01b15 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00773.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00773") +public class BenchmarkTest00773 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00773"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00774.java b/OWASP DATASET/BenchmarkTest00774.java new file mode 100644 index 0000000000000000000000000000000000000000..6b9f44e6b910bec1e3b7c244a91e58fe3a4c15a1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00774.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00774") +public class BenchmarkTest00774 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest00774"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00775.java b/OWASP DATASET/BenchmarkTest00775.java new file mode 100644 index 0000000000000000000000000000000000000000..eb9c740e44ce1c7e41583fc4eb7b653ea2e64228 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00775.java @@ -0,0 +1,183 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest00775") +public class BenchmarkTest00775 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00775" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00775" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00775" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00776.java b/OWASP DATASET/BenchmarkTest00776.java new file mode 100644 index 0000000000000000000000000000000000000000..a9e92ba0e01314a973dbe10dc2e2ce3557f10ad9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00776.java @@ -0,0 +1,180 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest00776") +public class BenchmarkTest00776 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00776" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00776" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00776" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00777.java b/OWASP DATASET/BenchmarkTest00777.java new file mode 100644 index 0000000000000000000000000000000000000000..fe03f8c4ccd042c7a32293314ecc2bd7462c3ff9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00777.java @@ -0,0 +1,179 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest00777") +public class BenchmarkTest00777 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00777" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00777" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00777" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "safe!"; + java.util.HashMap map4544 = new java.util.HashMap(); + map4544.put("keyA-4544", "a_Value"); // put some stuff in the collection + map4544.put("keyB-4544", param); // put it in a collection + map4544.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map4544.get("keyB-4544"); // get it back out + bar = (String) map4544.get("keyA-4544"); // get safe value back out + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00778.java b/OWASP DATASET/BenchmarkTest00778.java new file mode 100644 index 0000000000000000000000000000000000000000..40c9314b944b70064b0e9043058f184930dde450 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00778.java @@ -0,0 +1,178 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest00778") +public class BenchmarkTest00778 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00778" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00778" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00778" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00779.java b/OWASP DATASET/BenchmarkTest00779.java new file mode 100644 index 0000000000000000000000000000000000000000..1326ed1f866e7130f234f04d82af293cf62dc243 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00779.java @@ -0,0 +1,176 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest00779") +public class BenchmarkTest00779 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00779" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00779" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00779" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = param; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00780.java b/OWASP DATASET/BenchmarkTest00780.java new file mode 100644 index 0000000000000000000000000000000000000000..4848a707c55617868c2fcdc98c3d59c61f23952a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00780.java @@ -0,0 +1,151 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest00780") +public class BenchmarkTest00780 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00780" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00780" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00780" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = org.owasp.benchmark.helpers.Utils.getCipher(); + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00781.java b/OWASP DATASET/BenchmarkTest00781.java new file mode 100644 index 0000000000000000000000000000000000000000..9ec14d9a281eae004b1f24fe29444ccd28d3c28e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00781.java @@ -0,0 +1,142 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest00781") +public class BenchmarkTest00781 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00781" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00781" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00781" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00782.java b/OWASP DATASET/BenchmarkTest00782.java new file mode 100644 index 0000000000000000000000000000000000000000..fde8cf9d3cd75ad96e6a154eb22a7a1077f142f9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00782.java @@ -0,0 +1,153 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest00782") +public class BenchmarkTest00782 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00782" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00782" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00782" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "AES/CCM/NoPadding", java.security.Security.getProvider("BC")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00783.java b/OWASP DATASET/BenchmarkTest00783.java new file mode 100644 index 0000000000000000000000000000000000000000..bae0cc22a079ca805b247da6876b7a9121fac606 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00783.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00783") +public class BenchmarkTest00783 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00783" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00783" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00783" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "safe!"; + java.util.HashMap map2299 = new java.util.HashMap(); + map2299.put("keyA-2299", "a-Value"); // put some stuff in the collection + map2299.put("keyB-2299", param); // put it in a collection + map2299.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map2299.get("keyB-2299"); // get it back out + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(new java.io.File(fileName)); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting FileInputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00784.java b/OWASP DATASET/BenchmarkTest00784.java new file mode 100644 index 0000000000000000000000000000000000000000..a9c6f93f8274af47ee807e71b162363a165069ef --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00784.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00784") +public class BenchmarkTest00784 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00784" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00784" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00784" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(fileName); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00785.java b/OWASP DATASET/BenchmarkTest00785.java new file mode 100644 index 0000000000000000000000000000000000000000..7dfcbee2e84911b1a0e7a22f2c3533ba489857cf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00785.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00785") +public class BenchmarkTest00785 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00785" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00785" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00785" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "safe!"; + java.util.HashMap map59480 = new java.util.HashMap(); + map59480.put("keyA-59480", "a-Value"); // put some stuff in the collection + map59480.put("keyB-59480", param); // put it in a collection + map59480.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map59480.get("keyB-59480"); // get it back out + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName, false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00786.java b/OWASP DATASET/BenchmarkTest00786.java new file mode 100644 index 0000000000000000000000000000000000000000..9a004e3c20ae134646dcc8472927b46ae7da78c5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00786.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00786") +public class BenchmarkTest00786 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00786" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00786" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00786" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "safe!"; + java.util.HashMap map29957 = new java.util.HashMap(); + map29957.put("keyA-29957", "a_Value"); // put some stuff in the collection + map29957.put("keyB-29957", param); // put it in a collection + map29957.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map29957.get("keyB-29957"); // get it back out + bar = (String) map29957.get("keyA-29957"); // get safe value back out + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName, false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00787.java b/OWASP DATASET/BenchmarkTest00787.java new file mode 100644 index 0000000000000000000000000000000000000000..a2adf6a9a693c00d6d03ecbfcb5f4cc6da426506 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00787.java @@ -0,0 +1,105 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00787") +public class BenchmarkTest00787 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00787" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00787" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00787" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00788.java b/OWASP DATASET/BenchmarkTest00788.java new file mode 100644 index 0000000000000000000000000000000000000000..170dde74b55d134321e940b58ff38fe6911ccd04 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00788.java @@ -0,0 +1,100 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00788") +public class BenchmarkTest00788 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00788" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00788" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00788" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00789.java b/OWASP DATASET/BenchmarkTest00789.java new file mode 100644 index 0000000000000000000000000000000000000000..e674b769a5f55e7938044c97754d31bbe07fa6b7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00789.java @@ -0,0 +1,133 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00789") +public class BenchmarkTest00789 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00789" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00789" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00789" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00790.java b/OWASP DATASET/BenchmarkTest00790.java new file mode 100644 index 0000000000000000000000000000000000000000..55019c50738d3badb02d635f30deed12ff066a35 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00790.java @@ -0,0 +1,126 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00790") +public class BenchmarkTest00790 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00790" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00790" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00790" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00791.java b/OWASP DATASET/BenchmarkTest00791.java new file mode 100644 index 0000000000000000000000000000000000000000..bbfe4cc649c7d038fa8d2f0f5337be815926fef7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00791.java @@ -0,0 +1,127 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00791") +public class BenchmarkTest00791 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00791" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00791" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00791" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + try { + java.security.MessageDigest md = + java.security.MessageDigest.getInstance("SHA-512", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00792.java b/OWASP DATASET/BenchmarkTest00792.java new file mode 100644 index 0000000000000000000000000000000000000000..47cd8bfebb46ce7612f8c154ad44b2b5ba1b32ff --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00792.java @@ -0,0 +1,133 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00792") +public class BenchmarkTest00792 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00792" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00792" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00792" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "safe!"; + java.util.HashMap map53005 = new java.util.HashMap(); + map53005.put("keyA-53005", "a_Value"); // put some stuff in the collection + map53005.put("keyB-53005", param); // put it in a collection + map53005.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map53005.get("keyB-53005"); // get it back out + bar = (String) map53005.get("keyA-53005"); // get safe value back out + + try { + java.security.MessageDigest md = + java.security.MessageDigest.getInstance("SHA-512", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00793.java b/OWASP DATASET/BenchmarkTest00793.java new file mode 100644 index 0000000000000000000000000000000000000000..5a0d5c22697639f6499505a12bca0d5b5affb88a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00793.java @@ -0,0 +1,127 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00793") +public class BenchmarkTest00793 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00793" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00793" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00793" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + try { + java.security.MessageDigest md = + java.security.MessageDigest.getInstance("SHA-512", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00794.java b/OWASP DATASET/BenchmarkTest00794.java new file mode 100644 index 0000000000000000000000000000000000000000..b8c2e2a93ce4dc5d8aa28cb69286065eb2494ec7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00794.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00794") +public class BenchmarkTest00794 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00794" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00794" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00794" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00795.java b/OWASP DATASET/BenchmarkTest00795.java new file mode 100644 index 0000000000000000000000000000000000000000..9f62a6ff4e6945c8e73d602f22519f59bddaa6bc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00795.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00795") +public class BenchmarkTest00795 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00795" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00795" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00795" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-256"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00796.java b/OWASP DATASET/BenchmarkTest00796.java new file mode 100644 index 0000000000000000000000000000000000000000..49dcdcca32b9fe9878591d584890cf2195c15863 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00796.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-00/BenchmarkTest00796") +public class BenchmarkTest00796 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00796" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00796" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00796" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "safe!"; + java.util.HashMap map72213 = new java.util.HashMap(); + map72213.put("keyA-72213", "a-Value"); // put some stuff in the collection + map72213.put("keyB-72213", param); // put it in a collection + map72213.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map72213.get("keyB-72213"); // get it back out + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00797.java b/OWASP DATASET/BenchmarkTest00797.java new file mode 100644 index 0000000000000000000000000000000000000000..c4255758e31234bdb9dab4b81e1dc822413f928a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00797.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest00797") +public class BenchmarkTest00797 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00797" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00797" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00797" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz97281 = new StringBuilder(param); + bar = sbxyz97281.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00798.java b/OWASP DATASET/BenchmarkTest00798.java new file mode 100644 index 0000000000000000000000000000000000000000..c1f5845191f6a4ca03c830401b7b47ef01528907 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00798.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest00798") +public class BenchmarkTest00798 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00798" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00798" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00798" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz25489 = new StringBuilder(param); + bar = sbxyz25489.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00799.java b/OWASP DATASET/BenchmarkTest00799.java new file mode 100644 index 0000000000000000000000000000000000000000..52a7c5f6536fb9c973851ed876a1ac9a9cba92d7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00799.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00799") +public class BenchmarkTest00799 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00799" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00799" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00799" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + java.io.PrintWriter out = response.getWriter(); + out.write("\n\n\n

"); + out.format(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + out.write("\n

\n\n"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00800.java b/OWASP DATASET/BenchmarkTest00800.java new file mode 100644 index 0000000000000000000000000000000000000000..3bc52c19cc68f3b6ddfb77d15d86df800e5a2267 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00800.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00800") +public class BenchmarkTest00800 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00800" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00800" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00800" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().format("Formatted like: %1$s and %2$s.", obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00801.java b/OWASP DATASET/BenchmarkTest00801.java new file mode 100644 index 0000000000000000000000000000000000000000..1b775cbbe93206163fbe37e370e5acd592ef3f83 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00801.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00801") +public class BenchmarkTest00801 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00801" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00801" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00801" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = param; + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00802.java b/OWASP DATASET/BenchmarkTest00802.java new file mode 100644 index 0000000000000000000000000000000000000000..90c1b770a83cf6067f952d59e1e7207f270630ac --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00802.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00802") +public class BenchmarkTest00802 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00802" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00802" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00802" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar.toCharArray()); + } +} diff --git a/OWASP DATASET/BenchmarkTest00803.java b/OWASP DATASET/BenchmarkTest00803.java new file mode 100644 index 0000000000000000000000000000000000000000..adb0736ba27f295600c751b17b0cb95d6041d935 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00803.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00803") +public class BenchmarkTest00803 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00803" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00803" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00803" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = param; + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00804.java b/OWASP DATASET/BenchmarkTest00804.java new file mode 100644 index 0000000000000000000000000000000000000000..98dff6eb81ce4568f249177ddc4c9bdc7469f22c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00804.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00804") +public class BenchmarkTest00804 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00804" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00804" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00804" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + StringBuilder sbxyz12823 = new StringBuilder(param); + String bar = sbxyz12823.append("_SafeStuff").toString(); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00805.java b/OWASP DATASET/BenchmarkTest00805.java new file mode 100644 index 0000000000000000000000000000000000000000..8e32dbd8c1fef2962950c51d9a760f72572f581c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00805.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00805") +public class BenchmarkTest00805 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00805" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00805" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00805" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + // Chain a bunch of propagators in sequence + String a72616 = param; // assign + StringBuilder b72616 = new StringBuilder(a72616); // stick in stringbuilder + b72616.append(" SafeStuff"); // append some safe content + b72616.replace( + b72616.length() - "Chars".length(), + b72616.length(), + "Chars"); // replace some of the end content + java.util.HashMap map72616 = new java.util.HashMap(); + map72616.put("key72616", b72616.toString()); // put in a collection + String c72616 = (String) map72616.get("key72616"); // get it back out + String d72616 = c72616.substring(0, c72616.length() - 1); // extract most of it + String e72616 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d72616.getBytes()))); // B64 encode and decode it + String f72616 = e72616.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f72616); // reflection + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00806.java b/OWASP DATASET/BenchmarkTest00806.java new file mode 100644 index 0000000000000000000000000000000000000000..eb54a60cebab616981d2ecca31f7a8c0c52d7bb3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00806.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00806") +public class BenchmarkTest00806 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00806" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00806" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00806" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(java.util.Locale.US, bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00807.java b/OWASP DATASET/BenchmarkTest00807.java new file mode 100644 index 0000000000000000000000000000000000000000..aedb712a13d3efab35a92b3a263fb264205d82fc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00807.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00807") +public class BenchmarkTest00807 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00807" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00807" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00807" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(java.util.Locale.US, bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00808.java b/OWASP DATASET/BenchmarkTest00808.java new file mode 100644 index 0000000000000000000000000000000000000000..727ae9459de22606d5272dc63e3bac6ced1c9993 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00808.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00808") +public class BenchmarkTest00808 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00808" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00808" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00808" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00809.java b/OWASP DATASET/BenchmarkTest00809.java new file mode 100644 index 0000000000000000000000000000000000000000..3b1cd048bcc82a4fb9fb05555eb43213582fafda --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00809.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00809") +public class BenchmarkTest00809 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00809" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00809" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00809" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00810.java b/OWASP DATASET/BenchmarkTest00810.java new file mode 100644 index 0000000000000000000000000000000000000000..558e0bebf5cf93af7834f7b1ed7aff10666ec5c8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00810.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00810") +public class BenchmarkTest00810 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00810" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00810" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00810" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + StringBuilder sbxyz36624 = new StringBuilder(param); + String bar = sbxyz36624.append("_SafeStuff").toString(); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar.toCharArray()); + } +} diff --git a/OWASP DATASET/BenchmarkTest00811.java b/OWASP DATASET/BenchmarkTest00811.java new file mode 100644 index 0000000000000000000000000000000000000000..25e9a73467d59609140e2c8da3fc457988aec2f9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00811.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00811") +public class BenchmarkTest00811 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00811" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00811" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00811" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar.toCharArray()); + } +} diff --git a/OWASP DATASET/BenchmarkTest00812.java b/OWASP DATASET/BenchmarkTest00812.java new file mode 100644 index 0000000000000000000000000000000000000000..c160bcb183562d1c1493ee341e71b45952e68583 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00812.java @@ -0,0 +1,80 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00812") +public class BenchmarkTest00812 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00812" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00812" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00812" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00813.java b/OWASP DATASET/BenchmarkTest00813.java new file mode 100644 index 0000000000000000000000000000000000000000..6634dd55611b5d354d94e85d22c09e778bcbbc9c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00813.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00813") +public class BenchmarkTest00813 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00813" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00813" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00813" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar, 0, length); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00814.java b/OWASP DATASET/BenchmarkTest00814.java new file mode 100644 index 0000000000000000000000000000000000000000..ea80dbc0d3e55adc1b9effb1aab0448340798451 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00814.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00814") +public class BenchmarkTest00814 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00814" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00814" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00814" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(); + + pb.command(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00815.java b/OWASP DATASET/BenchmarkTest00815.java new file mode 100644 index 0000000000000000000000000000000000000000..1148cd403dbe5f836e15d33116ba02fd8ebf5a37 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00815.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00815") +public class BenchmarkTest00815 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00815" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00815" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00815" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = param; + + String a1 = ""; + String a2 = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + } else { + a1 = "sh"; + a2 = "-c"; + } + String[] args = {a1, a2, "echo " + bar}; + + ProcessBuilder pb = new ProcessBuilder(); + + pb.command(args); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00816.java b/OWASP DATASET/BenchmarkTest00816.java new file mode 100644 index 0000000000000000000000000000000000000000..eebb195025be2f864005fedc35ab43135cf48e28 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00816.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00816") +public class BenchmarkTest00816 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00816" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00816" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00816" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "safe!"; + java.util.HashMap map34260 = new java.util.HashMap(); + map34260.put("keyA-34260", "a-Value"); // put some stuff in the collection + map34260.put("keyB-34260", param); // put it in a collection + map34260.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map34260.get("keyB-34260"); // get it back out + + String a1 = ""; + String a2 = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + } else { + a1 = "sh"; + a2 = "-c"; + } + String[] args = {a1, a2, "echo " + bar}; + + ProcessBuilder pb = new ProcessBuilder(); + + pb.command(args); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00817.java b/OWASP DATASET/BenchmarkTest00817.java new file mode 100644 index 0000000000000000000000000000000000000000..0f44b17e3130bf9bd9f025334743f8e1ecfe8c1d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00817.java @@ -0,0 +1,141 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00817") +public class BenchmarkTest00817 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00817" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00817" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00817" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + // Chain a bunch of propagators in sequence + String a9795 = param; // assign + StringBuilder b9795 = new StringBuilder(a9795); // stick in stringbuilder + b9795.append(" SafeStuff"); // append some safe content + b9795.replace( + b9795.length() - "Chars".length(), + b9795.length(), + "Chars"); // replace some of the end content + java.util.HashMap map9795 = new java.util.HashMap(); + map9795.put("key9795", b9795.toString()); // put in a collection + String c9795 = (String) map9795.get("key9795"); // get it back out + String d9795 = c9795.substring(0, c9795.length() - 1); // extract most of it + String e9795 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d9795.getBytes()))); // B64 encode and decode it + String f9795 = e9795.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f9795); // reflection + + double value = new java.util.Random().nextDouble(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Donna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextDouble() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00818.java b/OWASP DATASET/BenchmarkTest00818.java new file mode 100644 index 0000000000000000000000000000000000000000..ec036e93d53ef82cb16bd925670567c0121d8aae --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00818.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00818") +public class BenchmarkTest00818 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00818" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00818" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00818" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + float rand = new java.util.Random().nextFloat(); + String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "Floyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00819.java b/OWASP DATASET/BenchmarkTest00819.java new file mode 100644 index 0000000000000000000000000000000000000000..06d9a146b06e173fe0edbb91f552a81b859db2f9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00819.java @@ -0,0 +1,126 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00819") +public class BenchmarkTest00819 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00819" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00819" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00819" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00820.java b/OWASP DATASET/BenchmarkTest00820.java new file mode 100644 index 0000000000000000000000000000000000000000..1443388284b1530365e61389f6fcf6d445351fa0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00820.java @@ -0,0 +1,101 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest00820") +public class BenchmarkTest00820 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00820" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00820" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00820" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = param; + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00821.java b/OWASP DATASET/BenchmarkTest00821.java new file mode 100644 index 0000000000000000000000000000000000000000..c238de35bdbe0ea7234d135b5b4a50a553bbf450 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00821.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest00821") +public class BenchmarkTest00821 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00821" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00821" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00821" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00822.java b/OWASP DATASET/BenchmarkTest00822.java new file mode 100644 index 0000000000000000000000000000000000000000..67f956bc12b8a1c238aec3ebce5da8d98a769b66 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00822.java @@ -0,0 +1,80 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00822") +public class BenchmarkTest00822 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00822" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00822" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00822" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write("Parameter value: " + bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00823.java b/OWASP DATASET/BenchmarkTest00823.java new file mode 100644 index 0000000000000000000000000000000000000000..21463d6be68a95b6cdc2924dd14f7fe8bc6829a1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00823.java @@ -0,0 +1,100 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00823") +public class BenchmarkTest00823 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00823" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00823" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00823" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00824.java b/OWASP DATASET/BenchmarkTest00824.java new file mode 100644 index 0000000000000000000000000000000000000000..8c1fb2f0658ae0cf2e9488089198409533d2d3f9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00824.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00824") +public class BenchmarkTest00824 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00824" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00824" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00824" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "safe!"; + java.util.HashMap map57450 = new java.util.HashMap(); + map57450.put("keyA-57450", "a-Value"); // put some stuff in the collection + map57450.put("keyB-57450", param); // put it in a collection + map57450.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map57450.get("keyB-57450"); // get it back out + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00825.java b/OWASP DATASET/BenchmarkTest00825.java new file mode 100644 index 0000000000000000000000000000000000000000..047e1847bfa8275b089455b6ede4a416878ab1e1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00825.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00825") +public class BenchmarkTest00825 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00825" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00825" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00825" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00826.java b/OWASP DATASET/BenchmarkTest00826.java new file mode 100644 index 0000000000000000000000000000000000000000..031fd0626e21bbdd4480c1a4d9c40952315c9af4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00826.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00826") +public class BenchmarkTest00826 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00826" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00826" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00826" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = + r.exec(cmd + bar, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00827.java b/OWASP DATASET/BenchmarkTest00827.java new file mode 100644 index 0000000000000000000000000000000000000000..a75a3f546915f6fa986802c0c1fd84c3f3b82ca7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00827.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-00/BenchmarkTest00827") +public class BenchmarkTest00827 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00827" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00827" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00827" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + try { + Process p = r.exec(cmd, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00828.java b/OWASP DATASET/BenchmarkTest00828.java new file mode 100644 index 0000000000000000000000000000000000000000..56ab923439158e0e2d0ae839825835639ba8a90a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00828.java @@ -0,0 +1,141 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00828") +public class BenchmarkTest00828 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00828" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00828" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00828" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + getNextNumber(numGen, randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeBystander"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } + + void getNextNumber(java.util.Random generator, byte[] barray) { + generator.nextBytes(barray); + } +} diff --git a/OWASP DATASET/BenchmarkTest00829.java b/OWASP DATASET/BenchmarkTest00829.java new file mode 100644 index 0000000000000000000000000000000000000000..39314b5b6afc22bfe5ede81dbe73c6f9de39671d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00829.java @@ -0,0 +1,154 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00829") +public class BenchmarkTest00829 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00829" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00829" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00829" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00830.java b/OWASP DATASET/BenchmarkTest00830.java new file mode 100644 index 0000000000000000000000000000000000000000..eb167247cf7791733aeb429f836cd45689cec728 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00830.java @@ -0,0 +1,132 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00830") +public class BenchmarkTest00830 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00830" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00830" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00830" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + try { + double stuff = java.security.SecureRandom.getInstance("SHA1PRNG").nextGaussian(); + String rememberMeKey = + Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "SafeGayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextGaussian() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextGaussian() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00831.java b/OWASP DATASET/BenchmarkTest00831.java new file mode 100644 index 0000000000000000000000000000000000000000..7287bc8f722387720feba154bc3638ce1ddf103a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00831.java @@ -0,0 +1,147 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00831") +public class BenchmarkTest00831 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00831" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00831" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00831" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + // Chain a bunch of propagators in sequence + String a97193 = param; // assign + StringBuilder b97193 = new StringBuilder(a97193); // stick in stringbuilder + b97193.append(" SafeStuff"); // append some safe content + b97193.replace( + b97193.length() - "Chars".length(), + b97193.length(), + "Chars"); // replace some of the end content + java.util.HashMap map97193 = new java.util.HashMap(); + map97193.put("key97193", b97193.toString()); // put in a collection + String c97193 = (String) map97193.get("key97193"); // get it back out + String d97193 = c97193.substring(0, c97193.length() - 1); // extract most of it + String e97193 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d97193.getBytes()))); // B64 encode and decode it + String f97193 = e97193.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g97193 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g97193); // reflection + + try { + int randNumber = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "SafeInga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt(int) - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt(int) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00832.java b/OWASP DATASET/BenchmarkTest00832.java new file mode 100644 index 0000000000000000000000000000000000000000..5253d462dea2df549e0c5de115e2d107b59202b5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00832.java @@ -0,0 +1,126 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00832") +public class BenchmarkTest00832 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00832" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00832" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00832" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = param; + + try { + int r = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "SafeIngrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00833.java b/OWASP DATASET/BenchmarkTest00833.java new file mode 100644 index 0000000000000000000000000000000000000000..1e38d8b1f263a7e4fbf2d4dd8cffc886944780e9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00833.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00833") +public class BenchmarkTest00833 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00833" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00833" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00833" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00834.java b/OWASP DATASET/BenchmarkTest00834.java new file mode 100644 index 0000000000000000000000000000000000000000..ee0b1f40bb5ae256b945f6544cc6e6e8492a7a18 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00834.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00834") +public class BenchmarkTest00834 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00834" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00834" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00834" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00835.java b/OWASP DATASET/BenchmarkTest00835.java new file mode 100644 index 0000000000000000000000000000000000000000..819846fbfceb6b6757835c8f7f0b908bd3a7d8cd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00835.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00835") +public class BenchmarkTest00835 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00835" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00835" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00835" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00836.java b/OWASP DATASET/BenchmarkTest00836.java new file mode 100644 index 0000000000000000000000000000000000000000..87a017aa4820fdc9d8245ac2412a49dca7cfe6b1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00836.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00836") +public class BenchmarkTest00836 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00836" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00836" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00836" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00837.java b/OWASP DATASET/BenchmarkTest00837.java new file mode 100644 index 0000000000000000000000000000000000000000..bebe5de008414f13d521a64e6348bcafea6f0003 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00837.java @@ -0,0 +1,98 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00837") +public class BenchmarkTest00837 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00837" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00837" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00837" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "safe!"; + java.util.HashMap map5936 = new java.util.HashMap(); + map5936.put("keyA-5936", "a_Value"); // put some stuff in the collection + map5936.put("keyB-5936", param); // put it in a collection + map5936.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map5936.get("keyB-5936"); // get it back out + bar = (String) map5936.get("keyA-5936"); // get safe value back out + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00838.java b/OWASP DATASET/BenchmarkTest00838.java new file mode 100644 index 0000000000000000000000000000000000000000..fdb384be59d937959e996453e2f507471d3e1c79 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00838.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00838") +public class BenchmarkTest00838 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00838" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00838" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00838" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00839.java b/OWASP DATASET/BenchmarkTest00839.java new file mode 100644 index 0000000000000000000000000000000000000000..513c5cc6550306fd71d8cf040caae0f28d00fdcd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00839.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00839") +public class BenchmarkTest00839 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00839" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00839" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00839" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, new String[] {"Column1", "Column2"}); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00840.java b/OWASP DATASET/BenchmarkTest00840.java new file mode 100644 index 0000000000000000000000000000000000000000..5d9c41032e56416209f3df29d5c6b9bfceca8484 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00840.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00840") +public class BenchmarkTest00840 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00840" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00840" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00840" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + // System.out.println("no results for query: " + sql + " because the Spring batchUpdate + // method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00841.java b/OWASP DATASET/BenchmarkTest00841.java new file mode 100644 index 0000000000000000000000000000000000000000..e5aeb06d95411b27561e5a5ed75fe743b9566f6e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00841.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00841") +public class BenchmarkTest00841 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00841" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00841" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00841" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + // System.out.println("no results for query: " + sql + " because the Spring batchUpdate + // method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00842.java b/OWASP DATASET/BenchmarkTest00842.java new file mode 100644 index 0000000000000000000000000000000000000000..cc11768ee6f29bcb5c3fbd1ca3b8f7a1338f9a26 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00842.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00842") +public class BenchmarkTest00842 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00842" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00842" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00842" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // int results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForInt(sql); + Integer results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Integer.class); + response.getWriter().println("Your results are: " + results); + // System.out.println("Your results are: " + results); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00843.java b/OWASP DATASET/BenchmarkTest00843.java new file mode 100644 index 0000000000000000000000000000000000000000..4fb1231c3119b65dd1da7c164123f12d9522fee5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00843.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00843") +public class BenchmarkTest00843 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00843" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00843" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00843" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "safe!"; + java.util.HashMap map12983 = new java.util.HashMap(); + map12983.put("keyA-12983", "a-Value"); // put some stuff in the collection + map12983.put("keyB-12983", param); // put it in a collection + map12983.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map12983.get("keyB-12983"); // get it back out + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // Long results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForLong(sql); + Long results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Long.class); + response.getWriter().println("Your results are: " + String.valueOf(results)); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00844.java b/OWASP DATASET/BenchmarkTest00844.java new file mode 100644 index 0000000000000000000000000000000000000000..ea003ae318736142f2e00e1f2882b901bdd24134 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00844.java @@ -0,0 +1,105 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00844") +public class BenchmarkTest00844 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00844" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00844" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00844" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + String sql = + "SELECT TOP 1 USERNAME from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + Object results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, new Object[] {}, String.class); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(results.toString())); + // System.out.println(results.toString()); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00845.java b/OWASP DATASET/BenchmarkTest00845.java new file mode 100644 index 0000000000000000000000000000000000000000..69a8ea505fcee534396f4971eaa1b50f8bcc76b0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00845.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00845") +public class BenchmarkTest00845 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00845" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00845" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00845" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + org.springframework.jdbc.support.rowset.SqlRowSet results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForRowSet(sql); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + while (results.next()) { + response.getWriter() + .println( + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(results.getString("USERNAME")) + + " "); + // System.out.println(results.getString("USERNAME")); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00846.java b/OWASP DATASET/BenchmarkTest00846.java new file mode 100644 index 0000000000000000000000000000000000000000..c0e6060a25c6c333cc0e14ec6985d5a48995c918 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00846.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00846") +public class BenchmarkTest00846 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00846" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00846" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00846" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = param; + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00847.java b/OWASP DATASET/BenchmarkTest00847.java new file mode 100644 index 0000000000000000000000000000000000000000..cbbcd334f9a73fbfb6ca4a736ba99328aa17328b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00847.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00847") +public class BenchmarkTest00847 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00847" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00847" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00847" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.addBatch(sql); + int[] counts = statement.executeBatch(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(sql, counts, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00848.java b/OWASP DATASET/BenchmarkTest00848.java new file mode 100644 index 0000000000000000000000000000000000000000..2f7827d649345cf26f23b479e977c8e106814770 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00848.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00848") +public class BenchmarkTest00848 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00848" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00848" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00848" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = param; + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.addBatch(sql); + int[] counts = statement.executeBatch(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(sql, counts, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00849.java b/OWASP DATASET/BenchmarkTest00849.java new file mode 100644 index 0000000000000000000000000000000000000000..f30a871195ff84a94cdff511d64851435ca83d0e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00849.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00849") +public class BenchmarkTest00849 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00849" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00849" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00849" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00850.java b/OWASP DATASET/BenchmarkTest00850.java new file mode 100644 index 0000000000000000000000000000000000000000..2620b83b739f53bc9bd41d5fa1767433fd94b93a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00850.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00850") +public class BenchmarkTest00850 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00850" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00850" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00850" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + java.sql.ResultSet rs = statement.executeQuery(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00851.java b/OWASP DATASET/BenchmarkTest00851.java new file mode 100644 index 0000000000000000000000000000000000000000..ba5bfe682c0b1547e6ebf4137ab5d64dbd2551f5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00851.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00851") +public class BenchmarkTest00851 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00851" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00851" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00851" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new String[] {"USERNAME", "PASSWORD"}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00852.java b/OWASP DATASET/BenchmarkTest00852.java new file mode 100644 index 0000000000000000000000000000000000000000..aca8d6a2ce9a948d5fffc8292147203fca3ee7ee --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00852.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest00852") +public class BenchmarkTest00852 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest00852" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest00852" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest00852" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = "safe!"; + java.util.HashMap map47458 = new java.util.HashMap(); + map47458.put("keyA-47458", "a_Value"); // put some stuff in the collection + map47458.put("keyB-47458", param); // put it in a collection + map47458.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map47458.get("keyB-47458"); // get it back out + bar = (String) map47458.get("keyA-47458"); // get safe value back out + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + String result = xp.evaluate(expression, xmlDocument); + + response.getWriter().println("Your query results are: " + result + "
"); + + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00853.java b/OWASP DATASET/BenchmarkTest00853.java new file mode 100644 index 0000000000000000000000000000000000000000..d766448df069107b1f5ba759751c4d0b987e8546 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00853.java @@ -0,0 +1,150 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest00853") +public class BenchmarkTest00853 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00853"); + + StringBuilder sbxyz83803 = new StringBuilder(param); + String bar = sbxyz83803.append("_SafeStuff").toString(); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "DES/CBC/PKCS5PADDING", java.security.Security.getProvider("SunJCE")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00854.java b/OWASP DATASET/BenchmarkTest00854.java new file mode 100644 index 0000000000000000000000000000000000000000..78d19843f642810138b045c3c66557a8067bd28e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00854.java @@ -0,0 +1,155 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest00854") +public class BenchmarkTest00854 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00854"); + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00855.java b/OWASP DATASET/BenchmarkTest00855.java new file mode 100644 index 0000000000000000000000000000000000000000..da6dafc517eca45778eb401b5bc8babdf40a413a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00855.java @@ -0,0 +1,163 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest00855") +public class BenchmarkTest00855 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00855"); + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00856.java b/OWASP DATASET/BenchmarkTest00856.java new file mode 100644 index 0000000000000000000000000000000000000000..ec0f4145e1d38ccd036a0df881e57b87c99ebf28 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00856.java @@ -0,0 +1,139 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest00856") +public class BenchmarkTest00856 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00856"); + + // Chain a bunch of propagators in sequence + String a98944 = param; // assign + StringBuilder b98944 = new StringBuilder(a98944); // stick in stringbuilder + b98944.append(" SafeStuff"); // append some safe content + b98944.replace( + b98944.length() - "Chars".length(), + b98944.length(), + "Chars"); // replace some of the end content + java.util.HashMap map98944 = new java.util.HashMap(); + map98944.put("key98944", b98944.toString()); // put in a collection + String c98944 = (String) map98944.get("key98944"); // get it back out + String d98944 = c98944.substring(0, c98944.length() - 1); // extract most of it + String e98944 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d98944.getBytes()))); // B64 encode and decode it + String f98944 = e98944.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f98944); // reflection + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00857.java b/OWASP DATASET/BenchmarkTest00857.java new file mode 100644 index 0000000000000000000000000000000000000000..f2d77cde5f97659cb1bac9a96882ba52ed0b7048 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00857.java @@ -0,0 +1,138 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest00857") +public class BenchmarkTest00857 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00857"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00858.java b/OWASP DATASET/BenchmarkTest00858.java new file mode 100644 index 0000000000000000000000000000000000000000..11ccf506e7bb5690ac16dfc169a6bd87dd3667c6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00858.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest00858") +public class BenchmarkTest00858 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00858"); + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "AES/CCM/NoPadding", java.security.Security.getProvider("BC")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00859.java b/OWASP DATASET/BenchmarkTest00859.java new file mode 100644 index 0000000000000000000000000000000000000000..355ba46ae92f26247c1ed344f35848f8329f74b4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00859.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest00859") +public class BenchmarkTest00859 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00859"); + + String bar = "safe!"; + java.util.HashMap map87594 = new java.util.HashMap(); + map87594.put("keyA-87594", "a-Value"); // put some stuff in the collection + map87594.put("keyB-87594", param); // put it in a collection + map87594.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map87594.get("keyB-87594"); // get it back out + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00860.java b/OWASP DATASET/BenchmarkTest00860.java new file mode 100644 index 0000000000000000000000000000000000000000..626151d82f295afd9916fcfa7291d43bcc629a24 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00860.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest00860") +public class BenchmarkTest00860 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00860"); + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + javax.naming.directory.DirContext ctx = ads.getDirContext(); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + bar + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + // System.out.println("Filter " + filter); + boolean found = false; + javax.naming.NamingEnumeration results = + ctx.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00861.java b/OWASP DATASET/BenchmarkTest00861.java new file mode 100644 index 0000000000000000000000000000000000000000..880591d51421ff2ae289a5de0b7b4c3c08130448 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00861.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest00861") +public class BenchmarkTest00861 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00861"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + javax.naming.directory.DirContext ctx = ads.getDirContext(); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person)(uid=" + bar + "))"; + // System.out.println("Filter " + filter); + boolean found = false; + javax.naming.NamingEnumeration results = + ctx.search(base, filter, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00862.java b/OWASP DATASET/BenchmarkTest00862.java new file mode 100644 index 0000000000000000000000000000000000000000..67bac891440318822696ebd20e52d5c7c70c700e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00862.java @@ -0,0 +1,71 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00862") +public class BenchmarkTest00862 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00862"); + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + java.io.File fileTarget = + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR, bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00863.java b/OWASP DATASET/BenchmarkTest00863.java new file mode 100644 index 0000000000000000000000000000000000000000..a2b25d823602d0766d7fbe0e6a5c0ca1e417ab3f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00863.java @@ -0,0 +1,67 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00863") +public class BenchmarkTest00863 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00863"); + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + java.io.File fileTarget = new java.io.File(bar, "/Test.txt"); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00864.java b/OWASP DATASET/BenchmarkTest00864.java new file mode 100644 index 0000000000000000000000000000000000000000..ec41b845c03c1920c9d6c44fe77456596cf13dd2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00864.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00864") +public class BenchmarkTest00864 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00864"); + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + java.io.File fileTarget = new java.io.File(bar, "/Test.txt"); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00865.java b/OWASP DATASET/BenchmarkTest00865.java new file mode 100644 index 0000000000000000000000000000000000000000..81a856851118db502c811c26cf73c9d4daa49638 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00865.java @@ -0,0 +1,98 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-00/BenchmarkTest00865") +public class BenchmarkTest00865 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00865"); + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + // FILE URIs are tricky because they are different between Mac and Windows because of lack + // of standardization. + // Mac requires an extra slash for some reason. + String startURIslashes = ""; + if (System.getProperty("os.name").indexOf("Windows") != -1) + if (System.getProperty("os.name").indexOf("Windows") != -1) startURIslashes = "/"; + else startURIslashes = "//"; + + try { + java.net.URI fileURI = + new java.net.URI( + "file", + null, + startURIslashes + + org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + .replace('\\', java.io.File.separatorChar) + .replace(' ', '_') + + bar, + null, + null); + java.io.File fileTarget = new java.io.File(fileURI); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } catch (java.net.URISyntaxException e) { + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00866.java b/OWASP DATASET/BenchmarkTest00866.java new file mode 100644 index 0000000000000000000000000000000000000000..e2584f98867379f0a8e1c9f7519917eaf84206d7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00866.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest00866") +public class BenchmarkTest00866 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00866"); + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName)); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00867.java b/OWASP DATASET/BenchmarkTest00867.java new file mode 100644 index 0000000000000000000000000000000000000000..ac280a242bf5458fdc3ac624ffef83209e4800bb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00867.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest00867") +public class BenchmarkTest00867 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00867"); + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + java.io.InputStream is = null; + + try { + java.nio.file.Path path = java.nio.file.Paths.get(fileName); + is = java.nio.file.Files.newInputStream(path, java.nio.file.StandardOpenOption.READ); + byte[] b = new byte[1000]; + int size = is.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + is.close(); + } catch (Exception e) { + System.out.println("Couldn't open InputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting InputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (is != null) { + try { + is.close(); + is = null; + } catch (Exception e) { + // we tried... + } + } + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00868.java b/OWASP DATASET/BenchmarkTest00868.java new file mode 100644 index 0000000000000000000000000000000000000000..f4ca9ed8cce7631f3bb85579e2cafc8be985529c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00868.java @@ -0,0 +1,131 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest00868") +public class BenchmarkTest00868 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00868"); + + // Chain a bunch of propagators in sequence + String a51118 = param; // assign + StringBuilder b51118 = new StringBuilder(a51118); // stick in stringbuilder + b51118.append(" SafeStuff"); // append some safe content + b51118.replace( + b51118.length() - "Chars".length(), + b51118.length(), + "Chars"); // replace some of the end content + java.util.HashMap map51118 = new java.util.HashMap(); + map51118.put("key51118", b51118.toString()); // put in a collection + String c51118 = (String) map51118.get("key51118"); // get it back out + String d51118 = c51118.substring(0, c51118.length() - 1); // extract most of it + String e51118 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d51118.getBytes()))); // B64 encode and decode it + String f51118 = e51118.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f51118); // reflection + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("SHA1", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00869.java b/OWASP DATASET/BenchmarkTest00869.java new file mode 100644 index 0000000000000000000000000000000000000000..d835cd39d414f815b74bbaf3ffcbfd62be8462bb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00869.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest00869") +public class BenchmarkTest00869 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00869"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("SHA1", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00870.java b/OWASP DATASET/BenchmarkTest00870.java new file mode 100644 index 0000000000000000000000000000000000000000..82565d6f37664e3156fd04da4a9023b0217e70bf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00870.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest00870") +public class BenchmarkTest00870 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00870"); + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00871.java b/OWASP DATASET/BenchmarkTest00871.java new file mode 100644 index 0000000000000000000000000000000000000000..6e435c0560db6bb34ece4f42e361cb6a1f323bb5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00871.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest00871") +public class BenchmarkTest00871 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00871"); + + String bar = "safe!"; + java.util.HashMap map42157 = new java.util.HashMap(); + map42157.put("keyA-42157", "a-Value"); // put some stuff in the collection + map42157.put("keyB-42157", param); // put it in a collection + map42157.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map42157.get("keyB-42157"); // get it back out + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00872.java b/OWASP DATASET/BenchmarkTest00872.java new file mode 100644 index 0000000000000000000000000000000000000000..05a722bb80565b5409e960153cce2029887dbfdc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00872.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest00872") +public class BenchmarkTest00872 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00872"); + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00873.java b/OWASP DATASET/BenchmarkTest00873.java new file mode 100644 index 0000000000000000000000000000000000000000..cd78577a433028de58abc1e7dfe532d4c3aedcdf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00873.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest00873") +public class BenchmarkTest00873 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00873"); + + String bar = "safe!"; + java.util.HashMap map58847 = new java.util.HashMap(); + map58847.put("keyA-58847", "a_Value"); // put some stuff in the collection + map58847.put("keyB-58847", param); // put it in a collection + map58847.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map58847.get("keyB-58847"); // get it back out + bar = (String) map58847.get("keyA-58847"); // get safe value back out + + try { + java.security.MessageDigest md = + java.security.MessageDigest.getInstance("SHA-512", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00874.java b/OWASP DATASET/BenchmarkTest00874.java new file mode 100644 index 0000000000000000000000000000000000000000..dea3e0f257704caf5069d16a490707ba08227530 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00874.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest00874") +public class BenchmarkTest00874 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00874"); + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + try { + java.security.MessageDigest md = + java.security.MessageDigest.getInstance("SHA-512", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00875.java b/OWASP DATASET/BenchmarkTest00875.java new file mode 100644 index 0000000000000000000000000000000000000000..52534ac267d0d4978dd6b5cc639ac5abff6768be --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00875.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest00875") +public class BenchmarkTest00875 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00875"); + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00876.java b/OWASP DATASET/BenchmarkTest00876.java new file mode 100644 index 0000000000000000000000000000000000000000..6f5fb85f6bc4b314868f7908d9d7d4c9275c0a1b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00876.java @@ -0,0 +1,107 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest00876") +public class BenchmarkTest00876 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00876"); + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00877.java b/OWASP DATASET/BenchmarkTest00877.java new file mode 100644 index 0000000000000000000000000000000000000000..4fd3e2658f596bd0d2dffc65e227be2f4cfa1320 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00877.java @@ -0,0 +1,122 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest00877") +public class BenchmarkTest00877 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00877"); + + // Chain a bunch of propagators in sequence + String a55741 = param; // assign + StringBuilder b55741 = new StringBuilder(a55741); // stick in stringbuilder + b55741.append(" SafeStuff"); // append some safe content + b55741.replace( + b55741.length() - "Chars".length(), + b55741.length(), + "Chars"); // replace some of the end content + java.util.HashMap map55741 = new java.util.HashMap(); + map55741.put("key55741", b55741.toString()); // put in a collection + String c55741 = (String) map55741.get("key55741"); // get it back out + String d55741 = c55741.substring(0, c55741.length() - 1); // extract most of it + String e55741 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d55741.getBytes()))); // B64 encode and decode it + String f55741 = e55741.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f55741); // reflection + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00878.java b/OWASP DATASET/BenchmarkTest00878.java new file mode 100644 index 0000000000000000000000000000000000000000..d81ddc6ea5c9b48b1853137a517152f1c83dbbc0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00878.java @@ -0,0 +1,105 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest00878") +public class BenchmarkTest00878 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00878"); + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00879.java b/OWASP DATASET/BenchmarkTest00879.java new file mode 100644 index 0000000000000000000000000000000000000000..0fce6dcbb24a2c350142fd16df2826562f9f6c18 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00879.java @@ -0,0 +1,59 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00879") +public class BenchmarkTest00879 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00879"); + + String bar = "safe!"; + java.util.HashMap map11407 = new java.util.HashMap(); + map11407.put("keyA-11407", "a_Value"); // put some stuff in the collection + map11407.put("keyB-11407", param); // put it in a collection + map11407.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map11407.get("keyB-11407"); // get it back out + bar = (String) map11407.get("keyA-11407"); // get safe value back out + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(java.util.Locale.US, bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00880.java b/OWASP DATASET/BenchmarkTest00880.java new file mode 100644 index 0000000000000000000000000000000000000000..f0078c868556b4140db4db33c41ef2d264b17d76 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00880.java @@ -0,0 +1,59 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00880") +public class BenchmarkTest00880 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00880"); + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar.toCharArray()); + } +} diff --git a/OWASP DATASET/BenchmarkTest00881.java b/OWASP DATASET/BenchmarkTest00881.java new file mode 100644 index 0000000000000000000000000000000000000000..b9706b8bc27da9ef0036de7e6bcc9e06fff32e05 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00881.java @@ -0,0 +1,57 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00881") +public class BenchmarkTest00881 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00881"); + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00882.java b/OWASP DATASET/BenchmarkTest00882.java new file mode 100644 index 0000000000000000000000000000000000000000..9cbb27768a6c168e3eaa0b519bf55d550a658ceb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00882.java @@ -0,0 +1,57 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00882") +public class BenchmarkTest00882 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00882"); + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00883.java b/OWASP DATASET/BenchmarkTest00883.java new file mode 100644 index 0000000000000000000000000000000000000000..64e5e3b2923bdb848058b3a91bed657ae3d40cd3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00883.java @@ -0,0 +1,73 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00883") +public class BenchmarkTest00883 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00883"); + + // Chain a bunch of propagators in sequence + String a69063 = param; // assign + StringBuilder b69063 = new StringBuilder(a69063); // stick in stringbuilder + b69063.append(" SafeStuff"); // append some safe content + b69063.replace( + b69063.length() - "Chars".length(), + b69063.length(), + "Chars"); // replace some of the end content + java.util.HashMap map69063 = new java.util.HashMap(); + map69063.put("key69063", b69063.toString()); // put in a collection + String c69063 = (String) map69063.get("key69063"); // get it back out + String d69063 = c69063.substring(0, c69063.length() - 1); // extract most of it + String e69063 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d69063.getBytes()))); // B64 encode and decode it + String f69063 = e69063.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f69063); // reflection + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00884.java b/OWASP DATASET/BenchmarkTest00884.java new file mode 100644 index 0000000000000000000000000000000000000000..e57555db1821bcc364e75b899d84bade251fadb6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00884.java @@ -0,0 +1,59 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00884") +public class BenchmarkTest00884 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00884"); + + String bar = "safe!"; + java.util.HashMap map26388 = new java.util.HashMap(); + map26388.put("keyA-26388", "a_Value"); // put some stuff in the collection + map26388.put("keyB-26388", param); // put it in a collection + map26388.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map26388.get("keyB-26388"); // get it back out + bar = (String) map26388.get("keyA-26388"); // get safe value back out + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00885.java b/OWASP DATASET/BenchmarkTest00885.java new file mode 100644 index 0000000000000000000000000000000000000000..98872719796019b883ac9c362ff24990f43d9007 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00885.java @@ -0,0 +1,57 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00885") +public class BenchmarkTest00885 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00885"); + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz28240 = new StringBuilder(param); + bar = sbxyz28240.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(java.util.Locale.US, bar, obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00886.java b/OWASP DATASET/BenchmarkTest00886.java new file mode 100644 index 0000000000000000000000000000000000000000..172fa39b8a4002b0385a7543f08e64198ce1d200 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00886.java @@ -0,0 +1,59 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00886") +public class BenchmarkTest00886 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00886"); + + String bar = "safe!"; + java.util.HashMap map8361 = new java.util.HashMap(); + map8361.put("keyA-8361", "a_Value"); // put some stuff in the collection + map8361.put("keyB-8361", param); // put it in a collection + map8361.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map8361.get("keyB-8361"); // get it back out + bar = (String) map8361.get("keyA-8361"); // get safe value back out + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {bar, "b"}; + response.getWriter().printf("Formatted like: %1$s and %2$s.", obj); + } +} diff --git a/OWASP DATASET/BenchmarkTest00887.java b/OWASP DATASET/BenchmarkTest00887.java new file mode 100644 index 0000000000000000000000000000000000000000..35b1dd2cd91d58175fd1291af27290f17c415b55 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00887.java @@ -0,0 +1,57 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00887") +public class BenchmarkTest00887 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00887"); + + String bar = "safe!"; + java.util.HashMap map39726 = new java.util.HashMap(); + map39726.put("keyA-39726", "a-Value"); // put some stuff in the collection + map39726.put("keyB-39726", param); // put it in a collection + map39726.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map39726.get("keyB-39726"); // get it back out + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar.toCharArray()); + } +} diff --git a/OWASP DATASET/BenchmarkTest00888.java b/OWASP DATASET/BenchmarkTest00888.java new file mode 100644 index 0000000000000000000000000000000000000000..cba1c0e0abc7902f25094807f2de09e89996cdbf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00888.java @@ -0,0 +1,52 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00888") +public class BenchmarkTest00888 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00888"); + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar.toCharArray()); + } +} diff --git a/OWASP DATASET/BenchmarkTest00889.java b/OWASP DATASET/BenchmarkTest00889.java new file mode 100644 index 0000000000000000000000000000000000000000..b026d7d9952fe4f2a866c831d6c11d55bfd8d4a0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00889.java @@ -0,0 +1,57 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00889") +public class BenchmarkTest00889 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00889"); + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } +} diff --git a/OWASP DATASET/BenchmarkTest00890.java b/OWASP DATASET/BenchmarkTest00890.java new file mode 100644 index 0000000000000000000000000000000000000000..78839311b2bbe7390be5c3efbc5be356d6f2355b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00890.java @@ -0,0 +1,57 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00890") +public class BenchmarkTest00890 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00890"); + + String bar = "safe!"; + java.util.HashMap map61765 = new java.util.HashMap(); + map61765.put("keyA-61765", "a-Value"); // put some stuff in the collection + map61765.put("keyB-61765", param); // put it in a collection + map61765.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map61765.get("keyB-61765"); // get it back out + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar.toCharArray()); + } +} diff --git a/OWASP DATASET/BenchmarkTest00891.java b/OWASP DATASET/BenchmarkTest00891.java new file mode 100644 index 0000000000000000000000000000000000000000..00bb190c615c670b44120b54a48637a7e3ff2578 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00891.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00891") +public class BenchmarkTest00891 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00891"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar.toCharArray(), 0, length); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00892.java b/OWASP DATASET/BenchmarkTest00892.java new file mode 100644 index 0000000000000000000000000000000000000000..7e9a0cf2b38235975b191f7e9f6981fa30f35ed6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00892.java @@ -0,0 +1,56 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00892") +public class BenchmarkTest00892 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00892"); + + String bar = param; + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar, 0, length); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00893.java b/OWASP DATASET/BenchmarkTest00893.java new file mode 100644 index 0000000000000000000000000000000000000000..f596efbf369676a7187786c0fb23503ebd76c735 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00893.java @@ -0,0 +1,61 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00893") +public class BenchmarkTest00893 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00893"); + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar, 0, length); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00894.java b/OWASP DATASET/BenchmarkTest00894.java new file mode 100644 index 0000000000000000000000000000000000000000..c91cc82b454b34aaadaa5ba9f3a5914750073fe4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00894.java @@ -0,0 +1,59 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest00894") +public class BenchmarkTest00894 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00894"); + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar, 0, length); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00895.java b/OWASP DATASET/BenchmarkTest00895.java new file mode 100644 index 0000000000000000000000000000000000000000..167381094f138e07ed9fb709f11ddc7c3bde4f00 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00895.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest00895") +public class BenchmarkTest00895 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00895"); + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00896.java b/OWASP DATASET/BenchmarkTest00896.java new file mode 100644 index 0000000000000000000000000000000000000000..73725abfd21b28186ea2150ed1b0c812b4b71b1b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00896.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest00896") +public class BenchmarkTest00896 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00896"); + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00897.java b/OWASP DATASET/BenchmarkTest00897.java new file mode 100644 index 0000000000000000000000000000000000000000..45ab031fabd16f82ca62f45f60ce8d238cea6e75 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00897.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest00897") +public class BenchmarkTest00897 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00897"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + String a1 = ""; + String a2 = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + } else { + a1 = "sh"; + a2 = "-c"; + } + String[] args = {a1, a2, "echo " + bar}; + + ProcessBuilder pb = new ProcessBuilder(args); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.lang.String[]) Test Case"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00898.java b/OWASP DATASET/BenchmarkTest00898.java new file mode 100644 index 0000000000000000000000000000000000000000..f28b515d76e346a8cefdb1d806148c14cf50e15e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00898.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00898") +public class BenchmarkTest00898 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00898"); + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + byte[] bytes = new byte[10]; + new java.util.Random().nextBytes(bytes); + String rememberMeKey = org.owasp.esapi.ESAPI.encoder().encodeForBase64(bytes, true); + + String user = "Byron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextBytes() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00899.java b/OWASP DATASET/BenchmarkTest00899.java new file mode 100644 index 0000000000000000000000000000000000000000..d602492d5764e421652def22818c9c27b2ea57b7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00899.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00899") +public class BenchmarkTest00899 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00899"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + double value = new java.util.Random().nextDouble(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Donna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextDouble() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00900.java b/OWASP DATASET/BenchmarkTest00900.java new file mode 100644 index 0000000000000000000000000000000000000000..02f56027046a6dc53d205812a47e8c0f21765009 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00900.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00900") +public class BenchmarkTest00900 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00900"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + double stuff = new java.util.Random().nextGaussian(); + String rememberMeKey = Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "Gayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter() + .println("Weak Randomness Test java.util.Random.nextGaussian() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00901.java b/OWASP DATASET/BenchmarkTest00901.java new file mode 100644 index 0000000000000000000000000000000000000000..05a8a4802e8f3f90bdd20f7ea4b307bf7759ac33 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00901.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00901") +public class BenchmarkTest00901 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00901"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + int randNumber = new java.util.Random().nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "Inga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt(int) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00902.java b/OWASP DATASET/BenchmarkTest00902.java new file mode 100644 index 0000000000000000000000000000000000000000..aef12c148713304dfda9b42a0bd9025ed1b17b67 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00902.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-01/BenchmarkTest00902") +public class BenchmarkTest00902 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00902"); + + String bar = "safe!"; + java.util.HashMap map21609 = new java.util.HashMap(); + map21609.put("keyA-21609", "a-Value"); // put some stuff in the collection + map21609.put("keyB-21609", param); // put it in a collection + map21609.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map21609.get("keyB-21609"); // get it back out + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00903.java b/OWASP DATASET/BenchmarkTest00903.java new file mode 100644 index 0000000000000000000000000000000000000000..477ab0229da432d2be3a136e25cf28bf50de6808 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00903.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest00903") +public class BenchmarkTest00903 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00903"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00904.java b/OWASP DATASET/BenchmarkTest00904.java new file mode 100644 index 0000000000000000000000000000000000000000..de89ec1a2cdd3b27381ffe04d91c60f292587bff --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00904.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest00904") +public class BenchmarkTest00904 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00904"); + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00905.java b/OWASP DATASET/BenchmarkTest00905.java new file mode 100644 index 0000000000000000000000000000000000000000..ef81c7193fd607afb1e5bf0a46aa9c9d2d91a72f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00905.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest00905") +public class BenchmarkTest00905 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00905"); + + String bar = param; + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ping -c1 "); + args = new String[] {a1, a2, cmd + bar}; + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00906.java b/OWASP DATASET/BenchmarkTest00906.java new file mode 100644 index 0000000000000000000000000000000000000000..c1257c933aaab45a0ad7907389e88eaad50d692f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00906.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest00906") +public class BenchmarkTest00906 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00906"); + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ping -c1 "); + args = new String[] {a1, a2, cmd + bar}; + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00907.java b/OWASP DATASET/BenchmarkTest00907.java new file mode 100644 index 0000000000000000000000000000000000000000..d85a72de93f19a017d147695ccc416ea925ecdd3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00907.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest00907") +public class BenchmarkTest00907 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00907"); + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ping -c1 "); + args = new String[] {a1, a2, cmd + bar}; + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00908.java b/OWASP DATASET/BenchmarkTest00908.java new file mode 100644 index 0000000000000000000000000000000000000000..921fd4d308834315c6ed3b8e1e17772904fe2066 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00908.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest00908") +public class BenchmarkTest00908 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00908"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00909.java b/OWASP DATASET/BenchmarkTest00909.java new file mode 100644 index 0000000000000000000000000000000000000000..1e575a2143c9f1c83207971a413c3b1af9153243 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00909.java @@ -0,0 +1,72 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest00909") +public class BenchmarkTest00909 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00909"); + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00910.java b/OWASP DATASET/BenchmarkTest00910.java new file mode 100644 index 0000000000000000000000000000000000000000..b1e2c965ac361e785826b4c5c47b0b2ba965d2d8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00910.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest00910") +public class BenchmarkTest00910 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00910"); + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = + r.exec(cmd + bar, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00911.java b/OWASP DATASET/BenchmarkTest00911.java new file mode 100644 index 0000000000000000000000000000000000000000..6971e4e2121f5635060f04818c8192df08cb846e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00911.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest00911") +public class BenchmarkTest00911 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00911"); + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00912.java b/OWASP DATASET/BenchmarkTest00912.java new file mode 100644 index 0000000000000000000000000000000000000000..7c1b407c05099dacc0d2adcdbd6ef0a6feb653f1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00912.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest00912") +public class BenchmarkTest00912 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00912"); + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00913.java b/OWASP DATASET/BenchmarkTest00913.java new file mode 100644 index 0000000000000000000000000000000000000000..c7ab70495c7e74ace340b7d0832518e12b6653e4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00913.java @@ -0,0 +1,131 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest00913") +public class BenchmarkTest00913 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00913"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00914.java b/OWASP DATASET/BenchmarkTest00914.java new file mode 100644 index 0000000000000000000000000000000000000000..600c8f462ba6f8f55fbb61a7ef7552447dd4c2b9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00914.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest00914") +public class BenchmarkTest00914 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00914"); + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + getNextNumber(numGen, randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeBystander"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } + + void getNextNumber(java.util.Random generator, byte[] barray) { + generator.nextBytes(barray); + } +} diff --git a/OWASP DATASET/BenchmarkTest00915.java b/OWASP DATASET/BenchmarkTest00915.java new file mode 100644 index 0000000000000000000000000000000000000000..3eb804abcf1c861140369e60702669a3158a8a38 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00915.java @@ -0,0 +1,107 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest00915") +public class BenchmarkTest00915 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00915"); + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00916.java b/OWASP DATASET/BenchmarkTest00916.java new file mode 100644 index 0000000000000000000000000000000000000000..11a617957818b2e6b3052ec0a11bcc726ff99032 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00916.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest00916") +public class BenchmarkTest00916 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00916"); + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00917.java b/OWASP DATASET/BenchmarkTest00917.java new file mode 100644 index 0000000000000000000000000000000000000000..6eff6423d5ddc5c1ebfac285f05536517ffe0457 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00917.java @@ -0,0 +1,118 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest00917") +public class BenchmarkTest00917 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00917"); + + String bar = "safe!"; + java.util.HashMap map5880 = new java.util.HashMap(); + map5880.put("keyA-5880", "a_Value"); // put some stuff in the collection + map5880.put("keyB-5880", param); // put it in a collection + map5880.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map5880.get("keyB-5880"); // get it back out + bar = (String) map5880.get("keyA-5880"); // get safe value back out + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00918.java b/OWASP DATASET/BenchmarkTest00918.java new file mode 100644 index 0000000000000000000000000000000000000000..014967b102054c91ed7f62eacc4b20d94828a650 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00918.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest00918") +public class BenchmarkTest00918 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00918"); + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00919.java b/OWASP DATASET/BenchmarkTest00919.java new file mode 100644 index 0000000000000000000000000000000000000000..f4ed897851557e89ed99eb0440617b23511c45c0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00919.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest00919") +public class BenchmarkTest00919 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00919"); + + String bar = param; + + try { + float rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextFloat(); + String rememberMeKey = + Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeFloyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextFloat() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextFloat() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00920.java b/OWASP DATASET/BenchmarkTest00920.java new file mode 100644 index 0000000000000000000000000000000000000000..e2ac6308345a3ec928d667fb5398fed4791f204d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00920.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest00920") +public class BenchmarkTest00920 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00920"); + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + try { + double stuff = java.security.SecureRandom.getInstance("SHA1PRNG").nextGaussian(); + String rememberMeKey = + Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "SafeGayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextGaussian() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextGaussian() executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00921.java b/OWASP DATASET/BenchmarkTest00921.java new file mode 100644 index 0000000000000000000000000000000000000000..40636751c9a80cba88d6c0472f08d80773c043b4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00921.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest00921") +public class BenchmarkTest00921 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00921"); + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + try { + int randNumber = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "SafeInga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt(int) - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt(int) executed"); + } +} diff --git a/OWASP DATASET/BenchmarkTest00922.java b/OWASP DATASET/BenchmarkTest00922.java new file mode 100644 index 0000000000000000000000000000000000000000..0544c6107b5696a99eb5293f4a3111e213e77060 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00922.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00922") +public class BenchmarkTest00922 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00922"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String^,java.lang.Object) + request.getSession().setAttribute(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: '10340' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00923.java b/OWASP DATASET/BenchmarkTest00923.java new file mode 100644 index 0000000000000000000000000000000000000000..e181d9882364cf11e2cf0d78bed8424775e3356c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00923.java @@ -0,0 +1,58 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00923") +public class BenchmarkTest00923 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00923"); + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } +} diff --git a/OWASP DATASET/BenchmarkTest00924.java b/OWASP DATASET/BenchmarkTest00924.java new file mode 100644 index 0000000000000000000000000000000000000000..d0664cb51eabeab36504705ea0959dc580f3350f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00924.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00924") +public class BenchmarkTest00924 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00924"); + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00925.java b/OWASP DATASET/BenchmarkTest00925.java new file mode 100644 index 0000000000000000000000000000000000000000..988638bb987fdca00a764f81ff2d7cbe138c1711 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00925.java @@ -0,0 +1,67 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00925") +public class BenchmarkTest00925 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00925"); + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = connection.prepareStatement(sql); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00926.java b/OWASP DATASET/BenchmarkTest00926.java new file mode 100644 index 0000000000000000000000000000000000000000..30e8fd41cbe38ff5999220aca58e86fd1c5a7845 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00926.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00926") +public class BenchmarkTest00926 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00926"); + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = connection.prepareStatement(sql); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00927.java b/OWASP DATASET/BenchmarkTest00927.java new file mode 100644 index 0000000000000000000000000000000000000000..27b2f2c443c550e88b1aff136e8c94c59f3cf636 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00927.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00927") +public class BenchmarkTest00927 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00927"); + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00928.java b/OWASP DATASET/BenchmarkTest00928.java new file mode 100644 index 0000000000000000000000000000000000000000..248fc78c23911999e1cd1587d85220bf7c254eaa --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00928.java @@ -0,0 +1,71 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00928") +public class BenchmarkTest00928 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00928"); + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00929.java b/OWASP DATASET/BenchmarkTest00929.java new file mode 100644 index 0000000000000000000000000000000000000000..5781c5c28f7559be5b34f38890bfa7ed22f68a1a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00929.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00929") +public class BenchmarkTest00929 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00929"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00930.java b/OWASP DATASET/BenchmarkTest00930.java new file mode 100644 index 0000000000000000000000000000000000000000..f655409ae637b9cc805d7595c9380228d6b137d7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00930.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00930") +public class BenchmarkTest00930 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00930"); + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + // System.out.println("no results for query: " + sql + " because the Spring batchUpdate + // method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00931.java b/OWASP DATASET/BenchmarkTest00931.java new file mode 100644 index 0000000000000000000000000000000000000000..f90e1d9ad2ae83f6b789f3bc9f6889f2b0f850d2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00931.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00931") +public class BenchmarkTest00931 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00931"); + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.execute(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring execute method doesn't return results."); + + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00932.java b/OWASP DATASET/BenchmarkTest00932.java new file mode 100644 index 0000000000000000000000000000000000000000..3f81ff42fe6bd85a60cb1ac174f504c57fe94827 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00932.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00932") +public class BenchmarkTest00932 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00932"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.query( + sql, + new org.springframework.jdbc.core.RowMapper() { + @Override + public String mapRow(java.sql.ResultSet rs, int rowNum) + throws java.sql.SQLException { + try { + return rs.getString("USERNAME"); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper + .hideSQLErrors) { + return "Error processing query."; + } else throw e; + } + } + }); + response.getWriter().println("Your results are: "); + + for (String s : results) { + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(s) + "
"); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00933.java b/OWASP DATASET/BenchmarkTest00933.java new file mode 100644 index 0000000000000000000000000000000000000000..40757c3adf7e7389ab8cae82bb0261f61ec46a9c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00933.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00933") +public class BenchmarkTest00933 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00933"); + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List> list = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForList(sql); + response.getWriter().println("Your results are:
"); + + // System.out.println("Your results are"); + + for (Object o : list) { + response.getWriter() + .println( + org.owasp.esapi.ESAPI.encoder().encodeForHTML(o.toString()) + + "
"); + // System.out.println(o.toString()); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00934.java b/OWASP DATASET/BenchmarkTest00934.java new file mode 100644 index 0000000000000000000000000000000000000000..cd8ea35bc250414ce05a64cabeb1750fd2228eb2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00934.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00934") +public class BenchmarkTest00934 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00934"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // Long results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForLong(sql); + Long results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Long.class); + response.getWriter().println("Your results are: " + String.valueOf(results)); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00935.java b/OWASP DATASET/BenchmarkTest00935.java new file mode 100644 index 0000000000000000000000000000000000000000..9b877a80f74af1e689a1ea0ecdd452d4b1061369 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00935.java @@ -0,0 +1,90 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-01/BenchmarkTest00935") +public class BenchmarkTest00935 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00935"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + String sql = + "SELECT TOP 1 userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.Map results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForMap(sql); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(results.toString())); + // System.out.println(results.toString()); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00936.java b/OWASP DATASET/BenchmarkTest00936.java new file mode 100644 index 0000000000000000000000000000000000000000..5ceb287b4a4355448f1de787eb89f156ae03d9d6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00936.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest00936") +public class BenchmarkTest00936 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00936"); + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00937.java b/OWASP DATASET/BenchmarkTest00937.java new file mode 100644 index 0000000000000000000000000000000000000000..0c42e5289985ea0f4b71884680250a947e65c294 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00937.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest00937") +public class BenchmarkTest00937 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00937"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00938.java b/OWASP DATASET/BenchmarkTest00938.java new file mode 100644 index 0000000000000000000000000000000000000000..eb94dd760f83397e26bd45604bee71edc4365e4b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00938.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest00938") +public class BenchmarkTest00938 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00938"); + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new String[] {"username", "password"}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00939.java b/OWASP DATASET/BenchmarkTest00939.java new file mode 100644 index 0000000000000000000000000000000000000000..5e50ed325a196a021f1d1955044be20ee1085495 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00939.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest00939") +public class BenchmarkTest00939 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00939"); + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00940.java b/OWASP DATASET/BenchmarkTest00940.java new file mode 100644 index 0000000000000000000000000000000000000000..8c6ee2a8abe3d905b366810faebcc056cf127943 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00940.java @@ -0,0 +1,73 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest00940") +public class BenchmarkTest00940 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00940"); + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new String[] {"USERNAME", "PASSWORD"}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00941.java b/OWASP DATASET/BenchmarkTest00941.java new file mode 100644 index 0000000000000000000000000000000000000000..d28cf455737955a2c06208eda69736b182c24f52 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00941.java @@ -0,0 +1,93 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest00941") +public class BenchmarkTest00941 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest00941"); + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + org.w3c.dom.NodeList nodeList = + (org.w3c.dom.NodeList) + xp.compile(expression) + .evaluate(xmlDocument, javax.xml.xpath.XPathConstants.NODESET); + + response.getWriter().println("Your query results are:
"); + + for (int i = 0; i < nodeList.getLength(); i++) { + org.w3c.dom.Element value = (org.w3c.dom.Element) nodeList.item(i); + response.getWriter().println(value.getTextContent() + "
"); + } + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } +} diff --git a/OWASP DATASET/BenchmarkTest00942.java b/OWASP DATASET/BenchmarkTest00942.java new file mode 100644 index 0000000000000000000000000000000000000000..edabdd97663a8c647ae921787edc21cb3e046c4d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00942.java @@ -0,0 +1,186 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest00942") +public class BenchmarkTest00942 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00942", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/crypto-01/BenchmarkTest00942.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00942")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00943.java b/OWASP DATASET/BenchmarkTest00943.java new file mode 100644 index 0000000000000000000000000000000000000000..7ea33e0c3f547212c3404b7c585ff511279ce6e9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00943.java @@ -0,0 +1,148 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest00943") +public class BenchmarkTest00943 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00943", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/crypto-01/BenchmarkTest00943.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00943")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = org.owasp.benchmark.helpers.Utils.getCipher(); + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00944.java b/OWASP DATASET/BenchmarkTest00944.java new file mode 100644 index 0000000000000000000000000000000000000000..a96c19cb02f272c1a989583ba00791f75481beb1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00944.java @@ -0,0 +1,140 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest00944") +public class BenchmarkTest00944 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00944", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/crypto-01/BenchmarkTest00944.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00944")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "AES/CCM/NoPadding", java.security.Security.getProvider("BC")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00945.java b/OWASP DATASET/BenchmarkTest00945.java new file mode 100644 index 0000000000000000000000000000000000000000..69b502d954da99a811d92c92ef914186261cf9ef --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00945.java @@ -0,0 +1,149 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest00945") +public class BenchmarkTest00945 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00945", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/crypto-01/BenchmarkTest00945.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00945")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00946.java b/OWASP DATASET/BenchmarkTest00946.java new file mode 100644 index 0000000000000000000000000000000000000000..8a48761126457ef498104636279135de59518bba --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00946.java @@ -0,0 +1,142 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest00946") +public class BenchmarkTest00946 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00946", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/crypto-01/BenchmarkTest00946.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00946")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00947.java b/OWASP DATASET/BenchmarkTest00947.java new file mode 100644 index 0000000000000000000000000000000000000000..abe6252c574d7bdc1ceedd3420a26b061469e52c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00947.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest00947") +public class BenchmarkTest00947 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00947", "Ms+Bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/ldapi-00/BenchmarkTest00947.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00947")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + javax.naming.directory.DirContext ctx = ads.getDirContext(); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + bar + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + // System.out.println("Filter " + filter); + boolean found = false; + javax.naming.NamingEnumeration results = + ctx.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00948.java b/OWASP DATASET/BenchmarkTest00948.java new file mode 100644 index 0000000000000000000000000000000000000000..be08aa50e1dc6cf8458df2d37a6f7bb7e776288c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00948.java @@ -0,0 +1,133 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest00948") +public class BenchmarkTest00948 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00948", "Ms+Bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/ldapi-00/BenchmarkTest00948.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00948")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + javax.naming.directory.DirContext ctx = ads.getDirContext(); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person)(uid=" + bar + "))"; + // System.out.println("Filter " + filter); + boolean found = false; + javax.naming.NamingEnumeration results = + ctx.search(base, filter, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map72608 = new java.util.HashMap(); + map72608.put("keyA-72608", "a_Value"); // put some stuff in the collection + map72608.put("keyB-72608", param); // put it in a collection + map72608.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map72608.get("keyB-72608"); // get it back out + bar = (String) map72608.get("keyA-72608"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00949.java b/OWASP DATASET/BenchmarkTest00949.java new file mode 100644 index 0000000000000000000000000000000000000000..0e393f0819ddf7f33cf6308952135b4b97d65168 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00949.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest00949") +public class BenchmarkTest00949 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00949", "FileName"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/pathtraver-01/BenchmarkTest00949.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00949")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + java.io.File fileTarget = + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR, bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00950.java b/OWASP DATASET/BenchmarkTest00950.java new file mode 100644 index 0000000000000000000000000000000000000000..21b522e8369992e5aaf76601fe7d8681679856e1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00950.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest00950") +public class BenchmarkTest00950 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00950", "FileName"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/pathtraver-01/BenchmarkTest00950.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00950")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + java.io.File fileTarget = new java.io.File(bar, "/Test.txt"); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00951.java b/OWASP DATASET/BenchmarkTest00951.java new file mode 100644 index 0000000000000000000000000000000000000000..07bb305764a79304ab88993b89c6296b595754e8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00951.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest00951") +public class BenchmarkTest00951 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00951", "FileName"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/pathtraver-01/BenchmarkTest00951.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00951")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + // FILE URIs are tricky because they are different between Mac and Windows because of lack + // of standardization. + // Mac requires an extra slash for some reason. + String startURIslashes = ""; + if (System.getProperty("os.name").indexOf("Windows") != -1) + if (System.getProperty("os.name").indexOf("Windows") != -1) startURIslashes = "/"; + else startURIslashes = "//"; + + try { + java.net.URI fileURI = + new java.net.URI( + "file:" + + startURIslashes + + org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + .replace('\\', '/') + .replace(' ', '_') + + bar); + java.io.File fileTarget = new java.io.File(fileURI); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } catch (java.net.URISyntaxException e) { + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00952.java b/OWASP DATASET/BenchmarkTest00952.java new file mode 100644 index 0000000000000000000000000000000000000000..194f107ef2723420f64b8386e09ad2b26bc37a47 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00952.java @@ -0,0 +1,136 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest00952") +public class BenchmarkTest00952 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00952", "FileName"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/pathtraver-01/BenchmarkTest00952.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00952")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + // FILE URIs are tricky because they are different between Mac and Windows because of lack + // of standardization. + // Mac requires an extra slash for some reason. + String startURIslashes = ""; + if (System.getProperty("os.name").indexOf("Windows") != -1) + if (System.getProperty("os.name").indexOf("Windows") != -1) startURIslashes = "/"; + else startURIslashes = "//"; + + try { + java.net.URI fileURI = + new java.net.URI( + "file", + null, + startURIslashes + + org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + .replace('\\', java.io.File.separatorChar) + .replace(' ', '_') + + bar, + null, + null); + java.io.File fileTarget = new java.io.File(fileURI); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } catch (java.net.URISyntaxException e) { + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00953.java b/OWASP DATASET/BenchmarkTest00953.java new file mode 100644 index 0000000000000000000000000000000000000000..24f827ae47a585f5a8c66a9818ef04d0a612340e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00953.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest00953") +public class BenchmarkTest00953 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00953", "FileName"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/pathtraver-01/BenchmarkTest00953.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00953")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + try ( + // Create the file first so the test won't throw an exception if it doesn't exist. + // Note: Don't actually do this because this method signature could cause a tool to find + // THIS file constructor + // as a vuln, rather than the File signature we are trying to actually test. + // If necessary, just run the benchmark twice. The 1st run should create all the necessary + // files. + // new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar).createNewFile(); + + java.io.FileOutputStream fos = + new java.io.FileOutputStream(new java.io.FileInputStream(fileName).getFD()); ) { + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00954.java b/OWASP DATASET/BenchmarkTest00954.java new file mode 100644 index 0000000000000000000000000000000000000000..68d74099401ec7e2fc594333b796f8cb3142b05a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00954.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest00954") +public class BenchmarkTest00954 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00954", "FileName"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/pathtraver-01/BenchmarkTest00954.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00954")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + try ( + // Create the file first so the test won't throw an exception if it doesn't exist. + // Note: Don't actually do this because this method signature could cause a tool to find + // THIS file constructor + // as a vuln, rather than the File signature we are trying to actually test. + // If necessary, just run the benchmark twice. The 1st run should create all the necessary + // files. + // new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar).createNewFile(); + + java.io.FileOutputStream fos = + new java.io.FileOutputStream(new java.io.FileInputStream(fileName).getFD()); ) { + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map9749 = new java.util.HashMap(); + map9749.put("keyA-9749", "a_Value"); // put some stuff in the collection + map9749.put("keyB-9749", param); // put it in a collection + map9749.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map9749.get("keyB-9749"); // get it back out + bar = (String) map9749.get("keyA-9749"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00955.java b/OWASP DATASET/BenchmarkTest00955.java new file mode 100644 index 0000000000000000000000000000000000000000..c84ef7cb2aadb390034510081d85717c582ebf72 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00955.java @@ -0,0 +1,105 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest00955") +public class BenchmarkTest00955 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00955", "FileName"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/pathtraver-01/BenchmarkTest00955.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00955")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + try ( + // Create the file first so the test won't throw an exception if it doesn't exist. + // Note: Don't actually do this because this method signature could cause a tool to find + // THIS file constructor + // as a vuln, rather than the File signature we are trying to actually test. + // If necessary, just run the benchmark twice. The 1st run should create all the necessary + // files. + // new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar).createNewFile(); + + java.io.FileOutputStream fos = + new java.io.FileOutputStream(new java.io.FileInputStream(fileName).getFD()); ) { + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00956.java b/OWASP DATASET/BenchmarkTest00956.java new file mode 100644 index 0000000000000000000000000000000000000000..875d0ccbb3d9061476ca20593e40d65e45b04493 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00956.java @@ -0,0 +1,105 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest00956") +public class BenchmarkTest00956 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00956", "FileName"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/pathtraver-01/BenchmarkTest00956.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00956")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + try ( + // Create the file first so the test won't throw an exception if it doesn't exist. + // Note: Don't actually do this because this method signature could cause a tool to find + // THIS file constructor + // as a vuln, rather than the File signature we are trying to actually test. + // If necessary, just run the benchmark twice. The 1st run should create all the necessary + // files. + // new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar).createNewFile(); + + java.io.FileOutputStream fos = + new java.io.FileOutputStream(new java.io.FileInputStream(fileName).getFD()); ) { + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00957.java b/OWASP DATASET/BenchmarkTest00957.java new file mode 100644 index 0000000000000000000000000000000000000000..55f1406de6bd25df91e5ebd12f7b748066b62ab8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00957.java @@ -0,0 +1,125 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest00957") +public class BenchmarkTest00957 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00957", "FileName"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/pathtraver-01/BenchmarkTest00957.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00957")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + java.io.InputStream is = null; + + try { + java.nio.file.Path path = java.nio.file.Paths.get(fileName); + is = java.nio.file.Files.newInputStream(path, java.nio.file.StandardOpenOption.READ); + byte[] b = new byte[1000]; + int size = is.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + is.close(); + } catch (Exception e) { + System.out.println("Couldn't open InputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting InputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (is != null) { + try { + is.close(); + is = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00958.java b/OWASP DATASET/BenchmarkTest00958.java new file mode 100644 index 0000000000000000000000000000000000000000..d520eaa57c3e764c51832e353f6c65bd3e7b54cb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00958.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest00958") +public class BenchmarkTest00958 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00958", "FileName"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/pathtraver-01/BenchmarkTest00958.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00958")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + java.io.InputStream is = null; + + try { + java.nio.file.Path path = java.nio.file.Paths.get(fileName); + is = java.nio.file.Files.newInputStream(path, java.nio.file.StandardOpenOption.READ); + byte[] b = new byte[1000]; + int size = is.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + is.close(); + } catch (Exception e) { + System.out.println("Couldn't open InputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting InputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (is != null) { + try { + is.close(); + is = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map37053 = new java.util.HashMap(); + map37053.put("keyA-37053", "a_Value"); // put some stuff in the collection + map37053.put("keyB-37053", param); // put it in a collection + map37053.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map37053.get("keyB-37053"); // get it back out + bar = (String) map37053.get("keyA-37053"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00959.java b/OWASP DATASET/BenchmarkTest00959.java new file mode 100644 index 0000000000000000000000000000000000000000..e2fe46e453b79ce9f496b3026e862afe669b07bc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00959.java @@ -0,0 +1,135 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest00959") +public class BenchmarkTest00959 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00959", "Ms+Bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/ldapi-00/BenchmarkTest00959.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00959")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + bar + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + + javax.naming.directory.DirContext ctx = ads.getDirContext(); + javax.naming.directory.InitialDirContext idc = + (javax.naming.directory.InitialDirContext) ctx; + boolean found = false; + javax.naming.NamingEnumeration results = + idc.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00960.java b/OWASP DATASET/BenchmarkTest00960.java new file mode 100644 index 0000000000000000000000000000000000000000..cf958884b598861b5e734ed533cba4c4664beab0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00960.java @@ -0,0 +1,133 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest00960") +public class BenchmarkTest00960 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00960", "anything"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-02/BenchmarkTest00960.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00960")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + double value = java.lang.Math.random(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Doug"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + response.getWriter().println("Weak Randomness Test java.lang.Math.random() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map19964 = new java.util.HashMap(); + map19964.put("keyA-19964", "a_Value"); // put some stuff in the collection + map19964.put("keyB-19964", param); // put it in a collection + map19964.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map19964.get("keyB-19964"); // get it back out + bar = (String) map19964.get("keyA-19964"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00961.java b/OWASP DATASET/BenchmarkTest00961.java new file mode 100644 index 0000000000000000000000000000000000000000..29ba4140377e9653648a98cf704fc0e9cf26e65a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00961.java @@ -0,0 +1,138 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest00961") +public class BenchmarkTest00961 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00961", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/hash-01/BenchmarkTest00961.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00961")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map47722 = new java.util.HashMap(); + map47722.put("keyA-47722", "a_Value"); // put some stuff in the collection + map47722.put("keyB-47722", param); // put it in a collection + map47722.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map47722.get("keyB-47722"); // get it back out + bar = (String) map47722.get("keyA-47722"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00962.java b/OWASP DATASET/BenchmarkTest00962.java new file mode 100644 index 0000000000000000000000000000000000000000..ca328b4764af5bcf23c5e527e067394063053e4b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00962.java @@ -0,0 +1,135 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest00962") +public class BenchmarkTest00962 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00962", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/hash-01/BenchmarkTest00962.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00962")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = + java.security.MessageDigest.getInstance("SHA-512", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00963.java b/OWASP DATASET/BenchmarkTest00963.java new file mode 100644 index 0000000000000000000000000000000000000000..92d5597e268a21a6ebcbcb0ce7c5af9d7020491f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00963.java @@ -0,0 +1,127 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest00963") +public class BenchmarkTest00963 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00963", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/hash-01/BenchmarkTest00963.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00963")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00964.java b/OWASP DATASET/BenchmarkTest00964.java new file mode 100644 index 0000000000000000000000000000000000000000..921bceab52e56794e0282c548aecdfb27ac3885b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00964.java @@ -0,0 +1,131 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest00964") +public class BenchmarkTest00964 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00964", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/hash-01/BenchmarkTest00964.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00964")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00965.java b/OWASP DATASET/BenchmarkTest00965.java new file mode 100644 index 0000000000000000000000000000000000000000..cb36981d2f77b0aa78c35a4e3ddfb8beae39c0c9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00965.java @@ -0,0 +1,136 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest00965") +public class BenchmarkTest00965 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00965", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/hash-01/BenchmarkTest00965.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00965")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map47189 = new java.util.HashMap(); + map47189.put("keyA-47189", "a-Value"); // put some stuff in the collection + map47189.put("keyB-47189", param); // put it in a collection + map47189.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map47189.get("keyB-47189"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00966.java b/OWASP DATASET/BenchmarkTest00966.java new file mode 100644 index 0000000000000000000000000000000000000000..f384468ec05c4be4d94218f3cb310d4137f8bc47 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00966.java @@ -0,0 +1,136 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest00966") +public class BenchmarkTest00966 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00966", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/hash-01/BenchmarkTest00966.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00966")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00967.java b/OWASP DATASET/BenchmarkTest00967.java new file mode 100644 index 0000000000000000000000000000000000000000..7293356639d3025ddbb048c6aa0f45ee811d340a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00967.java @@ -0,0 +1,141 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest00967") +public class BenchmarkTest00967 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00967", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/hash-01/BenchmarkTest00967.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00967")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00968.java b/OWASP DATASET/BenchmarkTest00968.java new file mode 100644 index 0000000000000000000000000000000000000000..8f08cb3fcdf92f45b805df86c736a6ce471a05e9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00968.java @@ -0,0 +1,101 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest00968") +public class BenchmarkTest00968 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00968", "ECHOOO"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/cmdi-01/BenchmarkTest00968.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00968")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00969.java b/OWASP DATASET/BenchmarkTest00969.java new file mode 100644 index 0000000000000000000000000000000000000000..7f22d1c2d380649d2196c7892e15cfaf16521355 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00969.java @@ -0,0 +1,122 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest00969") +public class BenchmarkTest00969 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00969", "ECHOOO"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/cmdi-01/BenchmarkTest00969.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00969")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a10263 = param; // assign + StringBuilder b10263 = new StringBuilder(a10263); // stick in stringbuilder + b10263.append(" SafeStuff"); // append some safe content + b10263.replace( + b10263.length() - "Chars".length(), + b10263.length(), + "Chars"); // replace some of the end content + java.util.HashMap map10263 = new java.util.HashMap(); + map10263.put("key10263", b10263.toString()); // put in a collection + String c10263 = (String) map10263.get("key10263"); // get it back out + String d10263 = c10263.substring(0, c10263.length() - 1); // extract most of it + String e10263 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d10263.getBytes()))); // B64 encode and decode it + String f10263 = e10263.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g10263 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g10263); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00970.java b/OWASP DATASET/BenchmarkTest00970.java new file mode 100644 index 0000000000000000000000000000000000000000..85aa5e1837450a665e8514155ade9e452f5f9c90 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00970.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest00970") +public class BenchmarkTest00970 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00970", "ECHOOO"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/cmdi-01/BenchmarkTest00970.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00970")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00971.java b/OWASP DATASET/BenchmarkTest00971.java new file mode 100644 index 0000000000000000000000000000000000000000..e150eb0ab2b4e0b2626e65d13956a1f331599085 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00971.java @@ -0,0 +1,134 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest00971") +public class BenchmarkTest00971 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00971", "does_not_matter"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-02/BenchmarkTest00971.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00971")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + double value = new java.util.Random().nextDouble(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Donna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextDouble() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00972.java b/OWASP DATASET/BenchmarkTest00972.java new file mode 100644 index 0000000000000000000000000000000000000000..cd955a1bee356a0a46782c37f695b5e0092d97a2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00972.java @@ -0,0 +1,133 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest00972") +public class BenchmarkTest00972 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00972", "does_not_matter"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-02/BenchmarkTest00972.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00972")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + double value = new java.util.Random().nextDouble(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Donna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextDouble() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map73877 = new java.util.HashMap(); + map73877.put("keyA-73877", "a_Value"); // put some stuff in the collection + map73877.put("keyB-73877", param); // put it in a collection + map73877.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map73877.get("keyB-73877"); // get it back out + bar = (String) map73877.get("keyA-73877"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00973.java b/OWASP DATASET/BenchmarkTest00973.java new file mode 100644 index 0000000000000000000000000000000000000000..792c74c173e539cc72c40c67f40899dc8a4087fe --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00973.java @@ -0,0 +1,127 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest00973") +public class BenchmarkTest00973 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00973", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-02/BenchmarkTest00973.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00973")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + double stuff = new java.util.Random().nextGaussian(); + String rememberMeKey = Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "Gayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter() + .println("Weak Randomness Test java.util.Random.nextGaussian() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00974.java b/OWASP DATASET/BenchmarkTest00974.java new file mode 100644 index 0000000000000000000000000000000000000000..6ae56d14bb8fedfcc84def6e2066dc43e3cdf34b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00974.java @@ -0,0 +1,133 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest00974") +public class BenchmarkTest00974 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00974", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-02/BenchmarkTest00974.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00974")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + int randNumber = new java.util.Random().nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "Inga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt(int) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00975.java b/OWASP DATASET/BenchmarkTest00975.java new file mode 100644 index 0000000000000000000000000000000000000000..25275cf1ba0d86ddc3375b95b2865683ecaa5b55 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00975.java @@ -0,0 +1,131 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest00975") +public class BenchmarkTest00975 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00975", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-02/BenchmarkTest00975.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00975")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + int randNumber = new java.util.Random().nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "Inga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt(int) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00976.java b/OWASP DATASET/BenchmarkTest00976.java new file mode 100644 index 0000000000000000000000000000000000000000..e71cdac3e63223f5832f0b7ab5c4d34b0582b9a8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00976.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest00976") +public class BenchmarkTest00976 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00976", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-02/BenchmarkTest00976.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00976")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00977.java b/OWASP DATASET/BenchmarkTest00977.java new file mode 100644 index 0000000000000000000000000000000000000000..6cfc9bd8cd92731061c3eb0b0bf2c5992f55de72 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00977.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest00977") +public class BenchmarkTest00977 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00977", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/securecookie-00/BenchmarkTest00977.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00977")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00978.java b/OWASP DATASET/BenchmarkTest00978.java new file mode 100644 index 0000000000000000000000000000000000000000..e0c51eb64ca973a4ef63902f7b662d054caeb554 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00978.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest00978") +public class BenchmarkTest00978 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00978", "localhost"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/cmdi-01/BenchmarkTest00978.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00978")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ping -c1 "); + args = new String[] {a1, a2, cmd + bar}; + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a60830 = param; // assign + StringBuilder b60830 = new StringBuilder(a60830); // stick in stringbuilder + b60830.append(" SafeStuff"); // append some safe content + b60830.replace( + b60830.length() - "Chars".length(), + b60830.length(), + "Chars"); // replace some of the end content + java.util.HashMap map60830 = new java.util.HashMap(); + map60830.put("key60830", b60830.toString()); // put in a collection + String c60830 = (String) map60830.get("key60830"); // get it back out + String d60830 = c60830.substring(0, c60830.length() - 1); // extract most of it + String e60830 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d60830.getBytes()))); // B64 encode and decode it + String f60830 = e60830.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g60830 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g60830); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00979.java b/OWASP DATASET/BenchmarkTest00979.java new file mode 100644 index 0000000000000000000000000000000000000000..ebf6fdd539fd2d59be4e44613dbb76d427e8f64f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00979.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest00979") +public class BenchmarkTest00979 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00979", "."); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/cmdi-01/BenchmarkTest00979.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00979")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00980.java b/OWASP DATASET/BenchmarkTest00980.java new file mode 100644 index 0000000000000000000000000000000000000000..89212fae69a238ecb99f9388c7855227044a2d5a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00980.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest00980") +public class BenchmarkTest00980 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00980", "FOO%3Decho+Injection"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/cmdi-01/BenchmarkTest00980.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00980")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00981.java b/OWASP DATASET/BenchmarkTest00981.java new file mode 100644 index 0000000000000000000000000000000000000000..c5d2ae0c1629ef2aeb1f26a38ce8b07fe3e104f9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00981.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest00981") +public class BenchmarkTest00981 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00981", "."); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/cmdi-01/BenchmarkTest00981.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00981")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00982.java b/OWASP DATASET/BenchmarkTest00982.java new file mode 100644 index 0000000000000000000000000000000000000000..a7fdbec6718f78a9e51f2ccc0a8a00e36511aaa1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00982.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest00982") +public class BenchmarkTest00982 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00982", "FOO%3Decho+Injection"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/cmdi-01/BenchmarkTest00982.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00982")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map20875 = new java.util.HashMap(); + map20875.put("keyA-20875", "a_Value"); // put some stuff in the collection + map20875.put("keyB-20875", param); // put it in a collection + map20875.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map20875.get("keyB-20875"); // get it back out + bar = (String) map20875.get("keyA-20875"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00983.java b/OWASP DATASET/BenchmarkTest00983.java new file mode 100644 index 0000000000000000000000000000000000000000..039fd35eab8bf99e69679ebd58792b779a49e57a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00983.java @@ -0,0 +1,100 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest00983") +public class BenchmarkTest00983 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00983", "FOO%3Decho+Injection"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/cmdi-01/BenchmarkTest00983.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00983")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00984.java b/OWASP DATASET/BenchmarkTest00984.java new file mode 100644 index 0000000000000000000000000000000000000000..80770adc19a49d2a8d5fbb0d301c9fccde1f7a99 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00984.java @@ -0,0 +1,161 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest00984") +public class BenchmarkTest00984 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00984", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-02/BenchmarkTest00984.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00984")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + double rand = getNextNumber(numGen); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonatella"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + double getNextNumber(java.util.Random generator) { + return generator.nextDouble(); + } + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a50427 = param; // assign + StringBuilder b50427 = new StringBuilder(a50427); // stick in stringbuilder + b50427.append(" SafeStuff"); // append some safe content + b50427.replace( + b50427.length() - "Chars".length(), + b50427.length(), + "Chars"); // replace some of the end content + java.util.HashMap map50427 = new java.util.HashMap(); + map50427.put("key50427", b50427.toString()); // put in a collection + String c50427 = (String) map50427.get("key50427"); // get it back out + String d50427 = c50427.substring(0, c50427.length() - 1); // extract most of it + String e50427 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d50427.getBytes()))); // B64 encode and decode it + String f50427 = e50427.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g50427 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g50427); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00985.java b/OWASP DATASET/BenchmarkTest00985.java new file mode 100644 index 0000000000000000000000000000000000000000..f1afe3457af3f23fc592446a5e2c9de6b2c1ab60 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00985.java @@ -0,0 +1,147 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest00985") +public class BenchmarkTest00985 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00985", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-02/BenchmarkTest00985.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00985")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + double rand = getNextNumber(numGen); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonatella"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + double getNextNumber(java.util.Random generator) { + return generator.nextDouble(); + } + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz77085 = new StringBuilder(param); + bar = + sbxyz77085 + .replace(param.length() - "Z".length(), param.length(), "Z") + .toString(); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00986.java b/OWASP DATASET/BenchmarkTest00986.java new file mode 100644 index 0000000000000000000000000000000000000000..35e7aec7effd7d6f66948f61ebbfc5f1a6b21836 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00986.java @@ -0,0 +1,143 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest00986") +public class BenchmarkTest00986 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00986", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-02/BenchmarkTest00986.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00986")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + double rand = getNextNumber(numGen); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonatella"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + double getNextNumber(java.util.Random generator) { + return generator.nextDouble(); + } + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00987.java b/OWASP DATASET/BenchmarkTest00987.java new file mode 100644 index 0000000000000000000000000000000000000000..5a112527cdcb97ac22348ba09ea1b98d68cfa666 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00987.java @@ -0,0 +1,138 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest00987") +public class BenchmarkTest00987 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00987", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-02/BenchmarkTest00987.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00987")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + float rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextFloat(); + String rememberMeKey = + Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeFloyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextFloat() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextFloat() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00988.java b/OWASP DATASET/BenchmarkTest00988.java new file mode 100644 index 0000000000000000000000000000000000000000..a1af647dd035d79e61d1291f6797eb2cd193fbbb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00988.java @@ -0,0 +1,138 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest00988") +public class BenchmarkTest00988 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00988", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-02/BenchmarkTest00988.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00988")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + double stuff = java.security.SecureRandom.getInstance("SHA1PRNG").nextGaussian(); + String rememberMeKey = + Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "SafeGayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextGaussian() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextGaussian() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00989.java b/OWASP DATASET/BenchmarkTest00989.java new file mode 100644 index 0000000000000000000000000000000000000000..a1f592860ee3f4c544496639a691d5711f55fd2f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00989.java @@ -0,0 +1,152 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest00989") +public class BenchmarkTest00989 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00989", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-02/BenchmarkTest00989.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00989")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + int randNumber = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "SafeInga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt(int) - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt(int) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a36538 = param; // assign + StringBuilder b36538 = new StringBuilder(a36538); // stick in stringbuilder + b36538.append(" SafeStuff"); // append some safe content + b36538.replace( + b36538.length() - "Chars".length(), + b36538.length(), + "Chars"); // replace some of the end content + java.util.HashMap map36538 = new java.util.HashMap(); + map36538.put("key36538", b36538.toString()); // put in a collection + String c36538 = (String) map36538.get("key36538"); // get it back out + String d36538 = c36538.substring(0, c36538.length() - 1); // extract most of it + String e36538 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d36538.getBytes()))); // B64 encode and decode it + String f36538 = e36538.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f36538); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00990.java b/OWASP DATASET/BenchmarkTest00990.java new file mode 100644 index 0000000000000000000000000000000000000000..ada688ffb3c3fe8056b857a02245af2afa235bc7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00990.java @@ -0,0 +1,132 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest00990") +public class BenchmarkTest00990 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00990", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-02/BenchmarkTest00990.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00990")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + int r = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "SafeIngrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00991.java b/OWASP DATASET/BenchmarkTest00991.java new file mode 100644 index 0000000000000000000000000000000000000000..1594460d8e8beceb190117e5740caeea22bb3a6a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00991.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00991") +public class BenchmarkTest00991 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00991", "color"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/trustbound-00/BenchmarkTest00991.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00991")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String^,java.lang.Object) + request.getSession().putValue(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: 10340 saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00992.java b/OWASP DATASET/BenchmarkTest00992.java new file mode 100644 index 0000000000000000000000000000000000000000..15fa167ba5af58b06a59cd5dc75201574701c0d2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00992.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00992") +public class BenchmarkTest00992 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00992", "color"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/trustbound-00/BenchmarkTest00992.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00992")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String^,java.lang.Object) + request.getSession().putValue(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: 10340 saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00993.java b/OWASP DATASET/BenchmarkTest00993.java new file mode 100644 index 0000000000000000000000000000000000000000..b4fd61317b235b25af785ae0cb89e5900cad4492 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00993.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00993") +public class BenchmarkTest00993 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00993", "my_user_id"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/trustbound-00/BenchmarkTest00993.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00993")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00994.java b/OWASP DATASET/BenchmarkTest00994.java new file mode 100644 index 0000000000000000000000000000000000000000..59ae63227649f70fb752985004642929c5e9bfe6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00994.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00994") +public class BenchmarkTest00994 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00994", "my_user_id"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/trustbound-00/BenchmarkTest00994.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00994")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00995.java b/OWASP DATASET/BenchmarkTest00995.java new file mode 100644 index 0000000000000000000000000000000000000000..c25441aff9bdda28751fb7f3f57fb536a7efdf55 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00995.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest00995") +public class BenchmarkTest00995 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest00995", "color"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/trustbound-00/BenchmarkTest00995.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00995")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String^,java.lang.Object) + request.getSession().setAttribute(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: '10340' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00996.java b/OWASP DATASET/BenchmarkTest00996.java new file mode 100644 index 0000000000000000000000000000000000000000..2b9e41e14efc5e10f1016e1c11f6acb3908e4386 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00996.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest00996") +public class BenchmarkTest00996 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie( + "BenchmarkTest00996", "verifyUserPassword%28%27foo%27%2C%27bar%27%29"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-02/BenchmarkTest00996.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00996")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = connection.prepareCall(sql); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00997.java b/OWASP DATASET/BenchmarkTest00997.java new file mode 100644 index 0000000000000000000000000000000000000000..6c7b31f6e1ee8cae80441702a2f5d04a5ac6b78e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00997.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest00997") +public class BenchmarkTest00997 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie( + "BenchmarkTest00997", "verifyUserPassword%28%27foo%27%2C%27bar%27%29"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-02/BenchmarkTest00997.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00997")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00998.java b/OWASP DATASET/BenchmarkTest00998.java new file mode 100644 index 0000000000000000000000000000000000000000..73c26ad08341eaabc359dbef90d26b2f9d44ccfb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00998.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest00998") +public class BenchmarkTest00998 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie( + "BenchmarkTest00998", "verifyUserPassword%28%27foo%27%2C%27bar%27%29"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-02/BenchmarkTest00998.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00998")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest00999.java b/OWASP DATASET/BenchmarkTest00999.java new file mode 100644 index 0000000000000000000000000000000000000000..94a7b8b61e89a758981d44f51d193f1538e95b49 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest00999.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest00999") +public class BenchmarkTest00999 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie( + "BenchmarkTest00999", "verifyUserPassword%28%27foo%27%2C%27bar%27%29"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-02/BenchmarkTest00999.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest00999")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01000.java b/OWASP DATASET/BenchmarkTest01000.java new file mode 100644 index 0000000000000000000000000000000000000000..d964166002f86fb6911f86641c353d2d01bcb731 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01000.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01000") +public class BenchmarkTest01000 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie( + "BenchmarkTest01000", "verifyUserPassword%28%27foo%27%2C%27bar%27%29"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-02/BenchmarkTest01000.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01000")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01001.java b/OWASP DATASET/BenchmarkTest01001.java new file mode 100644 index 0000000000000000000000000000000000000000..b3024e606ad782a70669075132a2b19f98f6a4d2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01001.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01001") +public class BenchmarkTest01001 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01001", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-02/BenchmarkTest01001.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01001")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = connection.prepareStatement(sql); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01002.java b/OWASP DATASET/BenchmarkTest01002.java new file mode 100644 index 0000000000000000000000000000000000000000..eee25d4fec68bb0d4ef30e1646eb677ee8cc3631 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01002.java @@ -0,0 +1,100 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01002") +public class BenchmarkTest01002 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01002", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-02/BenchmarkTest01002.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01002")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, new int[] {1, 2}); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01003.java b/OWASP DATASET/BenchmarkTest01003.java new file mode 100644 index 0000000000000000000000000000000000000000..79e20c2eb57ba6cefc689ce187737e695d107631 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01003.java @@ -0,0 +1,105 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01003") +public class BenchmarkTest01003 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01003", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-02/BenchmarkTest01003.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01003")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, new String[] {"Column1", "Column2"}); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01004.java b/OWASP DATASET/BenchmarkTest01004.java new file mode 100644 index 0000000000000000000000000000000000000000..771de318a942bf6b7e07aabd2c5757a2379d1d84 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01004.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01004") +public class BenchmarkTest01004 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01004", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-02/BenchmarkTest01004.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01004")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, new String[] {"Column1", "Column2"}); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01005.java b/OWASP DATASET/BenchmarkTest01005.java new file mode 100644 index 0000000000000000000000000000000000000000..0889432362dd7e2f9d31a862678dfd5ff81b154d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01005.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01005") +public class BenchmarkTest01005 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01005", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-02/BenchmarkTest01005.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01005")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + // System.out.println("no results for query: " + sql + " because the Spring batchUpdate + // method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01006.java b/OWASP DATASET/BenchmarkTest01006.java new file mode 100644 index 0000000000000000000000000000000000000000..cd63247e71b722278639a9a53bfe394bd85cf8f9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01006.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01006") +public class BenchmarkTest01006 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01006", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-02/BenchmarkTest01006.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01006")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // Long results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForLong(sql); + Long results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Long.class); + response.getWriter().println("Your results are: " + String.valueOf(results)); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map36088 = new java.util.HashMap(); + map36088.put("keyA-36088", "a-Value"); // put some stuff in the collection + map36088.put("keyB-36088", param); // put it in a collection + map36088.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map36088.get("keyB-36088"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01007.java b/OWASP DATASET/BenchmarkTest01007.java new file mode 100644 index 0000000000000000000000000000000000000000..7174b1aa4135edc1b7b01c07f5f06c6fe7e1e421 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01007.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01007") +public class BenchmarkTest01007 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01007", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-02/BenchmarkTest01007.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01007")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = + "SELECT TOP 1 userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.Map results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForMap(sql); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(results.toString())); + // System.out.println(results.toString()); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01008.java b/OWASP DATASET/BenchmarkTest01008.java new file mode 100644 index 0000000000000000000000000000000000000000..c5ab84f61e261c5b15b98737b2fedaaefe484a01 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01008.java @@ -0,0 +1,107 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01008") +public class BenchmarkTest01008 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01008", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-02/BenchmarkTest01008.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01008")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + org.springframework.jdbc.support.rowset.SqlRowSet results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForRowSet(sql); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + while (results.next()) { + response.getWriter() + .println( + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(results.getString("USERNAME")) + + " "); + // System.out.println(results.getString("USERNAME")); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01009.java b/OWASP DATASET/BenchmarkTest01009.java new file mode 100644 index 0000000000000000000000000000000000000000..c70a6b7bfc4c084a7666eece7e115f572f3ea28d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01009.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01009") +public class BenchmarkTest01009 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01009", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-02/BenchmarkTest01009.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01009")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + org.springframework.jdbc.support.rowset.SqlRowSet results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForRowSet(sql); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + while (results.next()) { + response.getWriter() + .println( + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(results.getString("USERNAME")) + + " "); + // System.out.println(results.getString("USERNAME")); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01010.java b/OWASP DATASET/BenchmarkTest01010.java new file mode 100644 index 0000000000000000000000000000000000000000..9e29c5f81e14a166ff8ef4ea6f80ffb501f2e965 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01010.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01010") +public class BenchmarkTest01010 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01010", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-02/BenchmarkTest01010.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01010")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01011.java b/OWASP DATASET/BenchmarkTest01011.java new file mode 100644 index 0000000000000000000000000000000000000000..9d4e34dab20906e2c1405b564d788a246e3e2f23 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01011.java @@ -0,0 +1,98 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01011") +public class BenchmarkTest01011 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01011", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-02/BenchmarkTest01011.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01011")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.addBatch(sql); + int[] counts = statement.executeBatch(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(sql, counts, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01012.java b/OWASP DATASET/BenchmarkTest01012.java new file mode 100644 index 0000000000000000000000000000000000000000..cf46c411d89b8290ae7fc2cdd00ecb69ce034af6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01012.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01012") +public class BenchmarkTest01012 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01012", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-02/BenchmarkTest01012.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01012")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01013.java b/OWASP DATASET/BenchmarkTest01013.java new file mode 100644 index 0000000000000000000000000000000000000000..d768a1066a06bfc1321749e0315481c684e65dc0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01013.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest01013") +public class BenchmarkTest01013 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01013", "2222"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/xpathi-00/BenchmarkTest01013.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01013")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + org.w3c.dom.NodeList nodeList = + (org.w3c.dom.NodeList) + xp.compile(expression) + .evaluate(xmlDocument, javax.xml.xpath.XPathConstants.NODESET); + + response.getWriter().println("Your query results are:
"); + + for (int i = 0; i < nodeList.getLength(); i++) { + org.w3c.dom.Element value = (org.w3c.dom.Element) nodeList.item(i); + response.getWriter().println(value.getTextContent() + "
"); + } + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01014.java b/OWASP DATASET/BenchmarkTest01014.java new file mode 100644 index 0000000000000000000000000000000000000000..1ea8bdfd1475bb65f49b278c5f4f531637eacc61 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01014.java @@ -0,0 +1,127 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest01014") +public class BenchmarkTest01014 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01014", "2222"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/xpathi-00/BenchmarkTest01014.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01014")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + String result = xp.evaluate(expression, xmlDocument); + + response.getWriter().println("Your query results are: " + result + "
"); + + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01015.java b/OWASP DATASET/BenchmarkTest01015.java new file mode 100644 index 0000000000000000000000000000000000000000..0a224e658056b1ab52b76707aa0678e66b108694 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01015.java @@ -0,0 +1,167 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01015") +public class BenchmarkTest01015 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01015") != null) { + param = request.getHeader("BenchmarkTest01015"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "DES/CBC/PKCS5PADDING", java.security.Security.getProvider("SunJCE")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01016.java b/OWASP DATASET/BenchmarkTest01016.java new file mode 100644 index 0000000000000000000000000000000000000000..5de89e0a26310f0dbe63d5d65972b0fb29c46bc1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01016.java @@ -0,0 +1,174 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01016") +public class BenchmarkTest01016 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01016") != null) { + param = request.getHeader("BenchmarkTest01016"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map24774 = new java.util.HashMap(); + map24774.put("keyA-24774", "a_Value"); // put some stuff in the collection + map24774.put("keyB-24774", param); // put it in a collection + map24774.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map24774.get("keyB-24774"); // get it back out + bar = (String) map24774.get("keyA-24774"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01017.java b/OWASP DATASET/BenchmarkTest01017.java new file mode 100644 index 0000000000000000000000000000000000000000..09eef64b6e9b765fe57dc4872c4aed3f2db49362 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01017.java @@ -0,0 +1,189 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01017") +public class BenchmarkTest01017 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01017") != null) { + param = request.getHeader("BenchmarkTest01017"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a27056 = param; // assign + StringBuilder b27056 = new StringBuilder(a27056); // stick in stringbuilder + b27056.append(" SafeStuff"); // append some safe content + b27056.replace( + b27056.length() - "Chars".length(), + b27056.length(), + "Chars"); // replace some of the end content + java.util.HashMap map27056 = new java.util.HashMap(); + map27056.put("key27056", b27056.toString()); // put in a collection + String c27056 = (String) map27056.get("key27056"); // get it back out + String d27056 = c27056.substring(0, c27056.length() - 1); // extract most of it + String e27056 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d27056.getBytes()))); // B64 encode and decode it + String f27056 = e27056.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g27056 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g27056); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01018.java b/OWASP DATASET/BenchmarkTest01018.java new file mode 100644 index 0000000000000000000000000000000000000000..ae80b050952aa3eaba0ce0c9d3363bb58f2e52d8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01018.java @@ -0,0 +1,134 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01018") +public class BenchmarkTest01018 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01018") != null) { + param = request.getHeader("BenchmarkTest01018"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01019.java b/OWASP DATASET/BenchmarkTest01019.java new file mode 100644 index 0000000000000000000000000000000000000000..0f3d50d248d4b25880c1aa0bca946a974440d57e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01019.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01019") +public class BenchmarkTest01019 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01019") != null) { + param = request.getHeader("BenchmarkTest01019"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "AES/CCM/NoPadding", java.security.Security.getProvider("BC")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01020.java b/OWASP DATASET/BenchmarkTest01020.java new file mode 100644 index 0000000000000000000000000000000000000000..17fbacd224e9ea76fd4bbcdfc20a9586164bb6ef --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01020.java @@ -0,0 +1,128 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01020") +public class BenchmarkTest01020 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01020") != null) { + param = request.getHeader("BenchmarkTest01020"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01021.java b/OWASP DATASET/BenchmarkTest01021.java new file mode 100644 index 0000000000000000000000000000000000000000..3c88951a3194e847a4164a800b0129152ad48cd7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01021.java @@ -0,0 +1,141 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01021") +public class BenchmarkTest01021 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01021") != null) { + param = request.getHeader("BenchmarkTest01021"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + // java.security.SecureRandom random = new java.security.SecureRandom(); + // byte[] iv = random.generateSeed(16); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg2", "AES/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map16616 = new java.util.HashMap(); + map16616.put("keyA-16616", "a_Value"); // put some stuff in the collection + map16616.put("keyB-16616", param); // put it in a collection + map16616.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map16616.get("keyB-16616"); // get it back out + bar = (String) map16616.get("keyA-16616"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01022.java b/OWASP DATASET/BenchmarkTest01022.java new file mode 100644 index 0000000000000000000000000000000000000000..e4273e020346db155c1958991c350d77941f1c39 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01022.java @@ -0,0 +1,140 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01022") +public class BenchmarkTest01022 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01022") != null) { + param = request.getHeader("BenchmarkTest01022"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + // java.security.SecureRandom random = new java.security.SecureRandom(); + // byte[] iv = random.generateSeed(16); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg2", "AES/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01023.java b/OWASP DATASET/BenchmarkTest01023.java new file mode 100644 index 0000000000000000000000000000000000000000..394763570544c2fdadef3c7aaf6c7121d85a3156 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01023.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest01023") +public class BenchmarkTest01023 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01023") != null) { + param = request.getHeader("BenchmarkTest01023"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + javax.naming.directory.DirContext ctx = ads.getDirContext(); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + bar + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + // System.out.println("Filter " + filter); + boolean found = false; + javax.naming.NamingEnumeration results = + ctx.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01024.java b/OWASP DATASET/BenchmarkTest01024.java new file mode 100644 index 0000000000000000000000000000000000000000..1847b41a262bf0b94c43f9b0773914e7e2a29012 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01024.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest01024") +public class BenchmarkTest01024 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01024") != null) { + param = request.getHeader("BenchmarkTest01024"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + javax.naming.directory.DirContext ctx = ads.getDirContext(); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + bar + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + // System.out.println("Filter " + filter); + boolean found = false; + javax.naming.NamingEnumeration results = + ctx.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01025.java b/OWASP DATASET/BenchmarkTest01025.java new file mode 100644 index 0000000000000000000000000000000000000000..d6dd08b6493aff87fd1b8e57145377b4a072f637 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01025.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01025") +public class BenchmarkTest01025 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01025") != null) { + param = request.getHeader("BenchmarkTest01025"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + java.io.File fileTarget = + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR, bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01026.java b/OWASP DATASET/BenchmarkTest01026.java new file mode 100644 index 0000000000000000000000000000000000000000..7fb206cc28ecf17924747a811583c05e3122f83d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01026.java @@ -0,0 +1,101 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01026") +public class BenchmarkTest01026 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01026") != null) { + param = request.getHeader("BenchmarkTest01026"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + java.io.File fileTarget = new java.io.File(bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a11433 = param; // assign + StringBuilder b11433 = new StringBuilder(a11433); // stick in stringbuilder + b11433.append(" SafeStuff"); // append some safe content + b11433.replace( + b11433.length() - "Chars".length(), + b11433.length(), + "Chars"); // replace some of the end content + java.util.HashMap map11433 = new java.util.HashMap(); + map11433.put("key11433", b11433.toString()); // put in a collection + String c11433 = (String) map11433.get("key11433"); // get it back out + String d11433 = c11433.substring(0, c11433.length() - 1); // extract most of it + String e11433 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d11433.getBytes()))); // B64 encode and decode it + String f11433 = e11433.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g11433 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g11433); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01027.java b/OWASP DATASET/BenchmarkTest01027.java new file mode 100644 index 0000000000000000000000000000000000000000..6d299801597a9345831277619e336356357ce93c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01027.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01027") +public class BenchmarkTest01027 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01027") != null) { + param = request.getHeader("BenchmarkTest01027"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + java.io.File fileTarget = new java.io.File(bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01028.java b/OWASP DATASET/BenchmarkTest01028.java new file mode 100644 index 0000000000000000000000000000000000000000..321b4efdd17e9d0b15fdbc8f521dab4654e8d798 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01028.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01028") +public class BenchmarkTest01028 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01028") != null) { + param = request.getHeader("BenchmarkTest01028"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // FILE URIs are tricky because they are different between Mac and Windows because of lack + // of standardization. + // Mac requires an extra slash for some reason. + String startURIslashes = ""; + if (System.getProperty("os.name").indexOf("Windows") != -1) + if (System.getProperty("os.name").indexOf("Windows") != -1) startURIslashes = "/"; + else startURIslashes = "//"; + + try { + java.net.URI fileURI = + new java.net.URI( + "file:" + + startURIslashes + + org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + .replace('\\', '/') + .replace(' ', '_') + + bar); + java.io.File fileTarget = new java.io.File(fileURI); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } catch (java.net.URISyntaxException e) { + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01029.java b/OWASP DATASET/BenchmarkTest01029.java new file mode 100644 index 0000000000000000000000000000000000000000..5b0f984f8b15dfe785a33f3cffe7c9200cc22347 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01029.java @@ -0,0 +1,105 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01029") +public class BenchmarkTest01029 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01029") != null) { + param = request.getHeader("BenchmarkTest01029"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // FILE URIs are tricky because they are different between Mac and Windows because of lack + // of standardization. + // Mac requires an extra slash for some reason. + String startURIslashes = ""; + if (System.getProperty("os.name").indexOf("Windows") != -1) + if (System.getProperty("os.name").indexOf("Windows") != -1) startURIslashes = "/"; + else startURIslashes = "//"; + + try { + java.net.URI fileURI = + new java.net.URI( + "file", + null, + startURIslashes + + org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + .replace('\\', java.io.File.separatorChar) + .replace(' ', '_') + + bar, + null, + null); + java.io.File fileTarget = new java.io.File(fileURI); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } catch (java.net.URISyntaxException e) { + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01030.java b/OWASP DATASET/BenchmarkTest01030.java new file mode 100644 index 0000000000000000000000000000000000000000..b19d1b78391ca3b7bb6f424551bbec216ed58dff --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01030.java @@ -0,0 +1,122 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01030") +public class BenchmarkTest01030 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01030") != null) { + param = request.getHeader("BenchmarkTest01030"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // FILE URIs are tricky because they are different between Mac and Windows because of lack + // of standardization. + // Mac requires an extra slash for some reason. + String startURIslashes = ""; + if (System.getProperty("os.name").indexOf("Windows") != -1) + if (System.getProperty("os.name").indexOf("Windows") != -1) startURIslashes = "/"; + else startURIslashes = "//"; + + try { + java.net.URI fileURI = + new java.net.URI( + "file", + null, + startURIslashes + + org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + .replace('\\', java.io.File.separatorChar) + .replace(' ', '_') + + bar, + null, + null); + java.io.File fileTarget = new java.io.File(fileURI); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } catch (java.net.URISyntaxException e) { + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01031.java b/OWASP DATASET/BenchmarkTest01031.java new file mode 100644 index 0000000000000000000000000000000000000000..2eace60d0fcae41fa73c4875062e43ab55deceb8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01031.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01031") +public class BenchmarkTest01031 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01031") != null) { + param = request.getHeader("BenchmarkTest01031"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(fileName); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01032.java b/OWASP DATASET/BenchmarkTest01032.java new file mode 100644 index 0000000000000000000000000000000000000000..5803e1eab2502792a34fb305e6526ac47f477eec --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01032.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01032") +public class BenchmarkTest01032 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01032") != null) { + param = request.getHeader("BenchmarkTest01032"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName), false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01033.java b/OWASP DATASET/BenchmarkTest01033.java new file mode 100644 index 0000000000000000000000000000000000000000..441af1d381522600595025b9b56529c4199eb769 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01033.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01033") +public class BenchmarkTest01033 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01033") != null) { + param = request.getHeader("BenchmarkTest01033"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName)); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01034.java b/OWASP DATASET/BenchmarkTest01034.java new file mode 100644 index 0000000000000000000000000000000000000000..4e5277f741d8c98c480740cc97f9c4417dc63f77 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01034.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01034") +public class BenchmarkTest01034 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01034") != null) { + param = request.getHeader("BenchmarkTest01034"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01035.java b/OWASP DATASET/BenchmarkTest01035.java new file mode 100644 index 0000000000000000000000000000000000000000..7b5680ec705b9472d995c625c017ed4691fe9c98 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01035.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01035") +public class BenchmarkTest01035 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01035") != null) { + param = request.getHeader("BenchmarkTest01035"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01036.java b/OWASP DATASET/BenchmarkTest01036.java new file mode 100644 index 0000000000000000000000000000000000000000..0104135b2abe678cbed4d7fd7b4fbd52f1c9e44a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01036.java @@ -0,0 +1,107 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01036") +public class BenchmarkTest01036 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01036") != null) { + param = request.getHeader("BenchmarkTest01036"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + java.io.InputStream is = null; + + try { + java.nio.file.Path path = java.nio.file.Paths.get(fileName); + is = java.nio.file.Files.newInputStream(path, java.nio.file.StandardOpenOption.READ); + byte[] b = new byte[1000]; + int size = is.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + is.close(); + } catch (Exception e) { + System.out.println("Couldn't open InputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting InputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (is != null) { + try { + is.close(); + is = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map8487 = new java.util.HashMap(); + map8487.put("keyA-8487", "a_Value"); // put some stuff in the collection + map8487.put("keyB-8487", param); // put it in a collection + map8487.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map8487.get("keyB-8487"); // get it back out + bar = (String) map8487.get("keyA-8487"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01037.java b/OWASP DATASET/BenchmarkTest01037.java new file mode 100644 index 0000000000000000000000000000000000000000..df121f33a5150065c5b8e114a61cb6ef354f4bc8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01037.java @@ -0,0 +1,138 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01037") +public class BenchmarkTest01037 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01037") != null) { + param = request.getHeader("BenchmarkTest01037"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = + java.security.MessageDigest.getInstance("SHA-512", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01038.java b/OWASP DATASET/BenchmarkTest01038.java new file mode 100644 index 0000000000000000000000000000000000000000..175c35430b56f0c9942140dddb79fa2aa1dda561 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01038.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01038") +public class BenchmarkTest01038 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01038") != null) { + param = request.getHeader("BenchmarkTest01038"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01039.java b/OWASP DATASET/BenchmarkTest01039.java new file mode 100644 index 0000000000000000000000000000000000000000..ec15135fb46ec765e9da5caceba2abf38ecad238 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01039.java @@ -0,0 +1,118 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01039") +public class BenchmarkTest01039 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01039") != null) { + param = request.getHeader("BenchmarkTest01039"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-256"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01040.java b/OWASP DATASET/BenchmarkTest01040.java new file mode 100644 index 0000000000000000000000000000000000000000..1129b0ec9703387730dfb7bcd447cf8972a89ded --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01040.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01040") +public class BenchmarkTest01040 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01040") != null) { + param = request.getHeader("BenchmarkTest01040"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-256"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz96551 = new StringBuilder(param); + String bar = sbxyz96551.append("_SafeStuff").toString(); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01041.java b/OWASP DATASET/BenchmarkTest01041.java new file mode 100644 index 0000000000000000000000000000000000000000..d2c16cdf745f2bcd3dcebba10f6799f7fd666d1f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01041.java @@ -0,0 +1,118 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01041") +public class BenchmarkTest01041 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01041") != null) { + param = request.getHeader("BenchmarkTest01041"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01042.java b/OWASP DATASET/BenchmarkTest01042.java new file mode 100644 index 0000000000000000000000000000000000000000..5fa97f7b4c32f914bb74c3dbedb0780a833e8e13 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01042.java @@ -0,0 +1,118 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01042") +public class BenchmarkTest01042 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01042") != null) { + param = request.getHeader("BenchmarkTest01042"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz89642 = new StringBuilder(param); + String bar = sbxyz89642.append("_SafeStuff").toString(); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01043.java b/OWASP DATASET/BenchmarkTest01043.java new file mode 100644 index 0000000000000000000000000000000000000000..050594ce6acba8f386c949e27942bfa7cdd253f6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01043.java @@ -0,0 +1,122 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01043") +public class BenchmarkTest01043 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01043") != null) { + param = request.getHeader("BenchmarkTest01043"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01044.java b/OWASP DATASET/BenchmarkTest01044.java new file mode 100644 index 0000000000000000000000000000000000000000..9ca6cfea3dba456fd7d60be6ee8dffe5190fd7d7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01044.java @@ -0,0 +1,136 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01044") +public class BenchmarkTest01044 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01044") != null) { + param = request.getHeader("BenchmarkTest01044"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01045.java b/OWASP DATASET/BenchmarkTest01045.java new file mode 100644 index 0000000000000000000000000000000000000000..a823021b1aaf5ddb0f11966e00a944decc4497a7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01045.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01045") +public class BenchmarkTest01045 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01045") != null) { + param = request.getHeader("BenchmarkTest01045"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01046.java b/OWASP DATASET/BenchmarkTest01046.java new file mode 100644 index 0000000000000000000000000000000000000000..9c5514c12807ce789416ce31ecc8dbeec6c1b99e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01046.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest01046") +public class BenchmarkTest01046 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + java.io.PrintWriter out = response.getWriter(); + out.write("\n\n\n

"); + out.format(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + out.write("\n

\n\n"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map95803 = new java.util.HashMap(); + map95803.put("keyA-95803", "a-Value"); // put some stuff in the collection + map95803.put("keyB-95803", param); // put it in a collection + map95803.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map95803.get("keyB-95803"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01047.java b/OWASP DATASET/BenchmarkTest01047.java new file mode 100644 index 0000000000000000000000000000000000000000..8753ffcd144d8c571f9dfc2eff7348685c87bbe7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01047.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-01/BenchmarkTest01047") +public class BenchmarkTest01047 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + java.io.PrintWriter out = response.getWriter(); + out.write("\n\n\n

"); + out.format(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + out.write("\n

\n\n"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz50709 = new StringBuilder(param); + bar = + sbxyz50709 + .replace(param.length() - "Z".length(), param.length(), "Z") + .toString(); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01048.java b/OWASP DATASET/BenchmarkTest01048.java new file mode 100644 index 0000000000000000000000000000000000000000..471020ced32e4400219ae6d44c592595168c2555 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01048.java @@ -0,0 +1,68 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01048") +public class BenchmarkTest01048 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(java.util.Locale.US, bar, obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01049.java b/OWASP DATASET/BenchmarkTest01049.java new file mode 100644 index 0000000000000000000000000000000000000000..8483295669b9414dfae1b620cdbe7426736c0cab --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01049.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01049") +public class BenchmarkTest01049 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().format("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01050.java b/OWASP DATASET/BenchmarkTest01050.java new file mode 100644 index 0000000000000000000000000000000000000000..ef46df752b61b67149ca4557c5823f21a669d38e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01050.java @@ -0,0 +1,68 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01050") +public class BenchmarkTest01050 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz75528 = new StringBuilder(param); + String bar = sbxyz75528.append("_SafeStuff").toString(); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01051.java b/OWASP DATASET/BenchmarkTest01051.java new file mode 100644 index 0000000000000000000000000000000000000000..0d836ccbea47aa9d594d829a1854deb93b9a0b92 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01051.java @@ -0,0 +1,73 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01051") +public class BenchmarkTest01051 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {bar, "b"}; + response.getWriter().printf("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01052.java b/OWASP DATASET/BenchmarkTest01052.java new file mode 100644 index 0000000000000000000000000000000000000000..728b8284b26cf730528b38484892b5a09eb0842c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01052.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01052") +public class BenchmarkTest01052 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(bar, obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01053.java b/OWASP DATASET/BenchmarkTest01053.java new file mode 100644 index 0000000000000000000000000000000000000000..d9e7dfcf9b5d893465765a83e967880930c24668 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01053.java @@ -0,0 +1,72 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01053") +public class BenchmarkTest01053 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01054.java b/OWASP DATASET/BenchmarkTest01054.java new file mode 100644 index 0000000000000000000000000000000000000000..62d80bd5c5d2d0c3ca1a8930e79a7b9ef12aca77 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01054.java @@ -0,0 +1,67 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01054") +public class BenchmarkTest01054 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01055.java b/OWASP DATASET/BenchmarkTest01055.java new file mode 100644 index 0000000000000000000000000000000000000000..22c49c297c2866280816a20ba29eb46f4eacd6b3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01055.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01055") +public class BenchmarkTest01055 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01056.java b/OWASP DATASET/BenchmarkTest01056.java new file mode 100644 index 0000000000000000000000000000000000000000..ea2e61787d10f91a61e786244a9acef695daac55 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01056.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01056") +public class BenchmarkTest01056 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar.toCharArray(), 0, length); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01057.java b/OWASP DATASET/BenchmarkTest01057.java new file mode 100644 index 0000000000000000000000000000000000000000..1ef5e5965a630ea1d21e14354e3c1bbe75c60ec6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01057.java @@ -0,0 +1,72 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01057") +public class BenchmarkTest01057 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01058.java b/OWASP DATASET/BenchmarkTest01058.java new file mode 100644 index 0000000000000000000000000000000000000000..1be2852716d2ab2ee8e0406e385f798bde018727 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01058.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01058") +public class BenchmarkTest01058 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01058") != null) { + param = request.getHeader("BenchmarkTest01058"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + byte[] bytes = new byte[10]; + new java.util.Random().nextBytes(bytes); + String rememberMeKey = org.owasp.esapi.ESAPI.encoder().encodeForBase64(bytes, true); + + String user = "Byron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextBytes() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz56505 = new StringBuilder(param); + String bar = sbxyz56505.append("_SafeStuff").toString(); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01059.java b/OWASP DATASET/BenchmarkTest01059.java new file mode 100644 index 0000000000000000000000000000000000000000..5910aca8dfc7b0e5bd35af5b1d942938e8ba15bd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01059.java @@ -0,0 +1,118 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01059") +public class BenchmarkTest01059 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01059") != null) { + param = request.getHeader("BenchmarkTest01059"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + double value = new java.util.Random().nextDouble(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Donna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextDouble() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01060.java b/OWASP DATASET/BenchmarkTest01060.java new file mode 100644 index 0000000000000000000000000000000000000000..246ba5eafc6de90939a94c643021b6a5ebecd5fd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01060.java @@ -0,0 +1,123 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01060") +public class BenchmarkTest01060 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01060") != null) { + param = request.getHeader("BenchmarkTest01060"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + float rand = new java.util.Random().nextFloat(); + String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "Floyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01061.java b/OWASP DATASET/BenchmarkTest01061.java new file mode 100644 index 0000000000000000000000000000000000000000..ff8b0dfd509ffcfda5f3198864d9480461b52aee --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01061.java @@ -0,0 +1,100 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest01061") +public class BenchmarkTest01061 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01061") != null) { + param = request.getHeader("BenchmarkTest01061"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz37461 = new StringBuilder(param); + bar = + sbxyz37461 + .replace(param.length() - "Z".length(), param.length(), "Z") + .toString(); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01062.java b/OWASP DATASET/BenchmarkTest01062.java new file mode 100644 index 0000000000000000000000000000000000000000..caea71c8d2e199951c415f69a653016d1e17d676 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01062.java @@ -0,0 +1,100 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest01062") +public class BenchmarkTest01062 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01062") != null) { + param = request.getHeader("BenchmarkTest01062"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01063.java b/OWASP DATASET/BenchmarkTest01063.java new file mode 100644 index 0000000000000000000000000000000000000000..0a02f0f4dcd0bae26d47454a23682badf9de0dc1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01063.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01063") +public class BenchmarkTest01063 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write("Parameter value: " + bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a92400 = param; // assign + StringBuilder b92400 = new StringBuilder(a92400); // stick in stringbuilder + b92400.append(" SafeStuff"); // append some safe content + b92400.replace( + b92400.length() - "Chars".length(), + b92400.length(), + "Chars"); // replace some of the end content + java.util.HashMap map92400 = new java.util.HashMap(); + map92400.put("key92400", b92400.toString()); // put in a collection + String c92400 = (String) map92400.get("key92400"); // get it back out + String d92400 = c92400.substring(0, c92400.length() - 1); // extract most of it + String e92400 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d92400.getBytes()))); // B64 encode and decode it + String f92400 = e92400.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f92400); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01064.java b/OWASP DATASET/BenchmarkTest01064.java new file mode 100644 index 0000000000000000000000000000000000000000..c5b774f8bb0df8eddab1bf7e9463a7d142d5293d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01064.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01064") +public class BenchmarkTest01064 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01064") != null) { + param = request.getHeader("BenchmarkTest01064"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map72463 = new java.util.HashMap(); + map72463.put("keyA-72463", "a-Value"); // put some stuff in the collection + map72463.put("keyB-72463", param); // put it in a collection + map72463.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map72463.get("keyB-72463"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01065.java b/OWASP DATASET/BenchmarkTest01065.java new file mode 100644 index 0000000000000000000000000000000000000000..5e682e30ff7e2d5f1f76636aba8e79686fa982d3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01065.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01065") +public class BenchmarkTest01065 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01065") != null) { + param = request.getHeader("BenchmarkTest01065"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ping -c1 "); + args = new String[] {a1, a2, cmd + bar}; + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01066.java b/OWASP DATASET/BenchmarkTest01066.java new file mode 100644 index 0000000000000000000000000000000000000000..c6b5b67863555b4a2d09542c77240243bd03e964 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01066.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01066") +public class BenchmarkTest01066 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01066") != null) { + param = request.getHeader("BenchmarkTest01066"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01067.java b/OWASP DATASET/BenchmarkTest01067.java new file mode 100644 index 0000000000000000000000000000000000000000..836347a1e5b7470b7a08c14905173bd62388635d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01067.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01067") +public class BenchmarkTest01067 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01067") != null) { + param = request.getHeader("BenchmarkTest01067"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01068.java b/OWASP DATASET/BenchmarkTest01068.java new file mode 100644 index 0000000000000000000000000000000000000000..43e80840fdce8f773ed1208ccfeb216b0fda2a33 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01068.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01068") +public class BenchmarkTest01068 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01068") != null) { + param = request.getHeader("BenchmarkTest01068"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = + r.exec(cmd + bar, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01069.java b/OWASP DATASET/BenchmarkTest01069.java new file mode 100644 index 0000000000000000000000000000000000000000..91616cd366fb1cc85e1174e44ad12b8919d4e8ee --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01069.java @@ -0,0 +1,127 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01069") +public class BenchmarkTest01069 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01069") != null) { + param = request.getHeader("BenchmarkTest01069"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01070.java b/OWASP DATASET/BenchmarkTest01070.java new file mode 100644 index 0000000000000000000000000000000000000000..5a1294825e281460cd853d2751b10d6079c6f79d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01070.java @@ -0,0 +1,150 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01070") +public class BenchmarkTest01070 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01070") != null) { + param = request.getHeader("BenchmarkTest01070"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + getNextNumber(numGen, randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeBystander"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + void getNextNumber(java.util.Random generator, byte[] barray) { + generator.nextBytes(barray); + } + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a85812 = param; // assign + StringBuilder b85812 = new StringBuilder(a85812); // stick in stringbuilder + b85812.append(" SafeStuff"); // append some safe content + b85812.replace( + b85812.length() - "Chars".length(), + b85812.length(), + "Chars"); // replace some of the end content + java.util.HashMap map85812 = new java.util.HashMap(); + map85812.put("key85812", b85812.toString()); // put in a collection + String c85812 = (String) map85812.get("key85812"); // get it back out + String d85812 = c85812.substring(0, c85812.length() - 1); // extract most of it + String e85812 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d85812.getBytes()))); // B64 encode and decode it + String f85812 = e85812.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f85812); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01071.java b/OWASP DATASET/BenchmarkTest01071.java new file mode 100644 index 0000000000000000000000000000000000000000..4d1b5684e315f267b7133c18e036167edc7193af --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01071.java @@ -0,0 +1,133 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01071") +public class BenchmarkTest01071 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01071") != null) { + param = request.getHeader("BenchmarkTest01071"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + getNextNumber(numGen, randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeBystander"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + void getNextNumber(java.util.Random generator, byte[] barray) { + generator.nextBytes(barray); + } + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01072.java b/OWASP DATASET/BenchmarkTest01072.java new file mode 100644 index 0000000000000000000000000000000000000000..56049dc4f7d42ccd40c14ae6fefa811bc57d9e39 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01072.java @@ -0,0 +1,133 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01072") +public class BenchmarkTest01072 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01072") != null) { + param = request.getHeader("BenchmarkTest01072"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + double rand = getNextNumber(numGen); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonatella"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + double getNextNumber(java.util.Random generator) { + return generator.nextDouble(); + } + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01073.java b/OWASP DATASET/BenchmarkTest01073.java new file mode 100644 index 0000000000000000000000000000000000000000..4a8086a9895dc539023fd953f4097a85f6d9ff25 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01073.java @@ -0,0 +1,146 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01073") +public class BenchmarkTest01073 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01073") != null) { + param = request.getHeader("BenchmarkTest01073"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01074.java b/OWASP DATASET/BenchmarkTest01074.java new file mode 100644 index 0000000000000000000000000000000000000000..e2d9c9f0a45683f513a53b8d28dea57ffd908ca2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01074.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01074") +public class BenchmarkTest01074 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01074") != null) { + param = request.getHeader("BenchmarkTest01074"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + float rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextFloat(); + String rememberMeKey = + Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeFloyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextFloat() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextFloat() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01075.java b/OWASP DATASET/BenchmarkTest01075.java new file mode 100644 index 0000000000000000000000000000000000000000..b215c3aa16659c09a3b51517d4af585e502d7b6c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01075.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01075") +public class BenchmarkTest01075 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01075") != null) { + param = request.getHeader("BenchmarkTest01075"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + double stuff = java.security.SecureRandom.getInstance("SHA1PRNG").nextGaussian(); + String rememberMeKey = + Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "SafeGayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextGaussian() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextGaussian() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01076.java b/OWASP DATASET/BenchmarkTest01076.java new file mode 100644 index 0000000000000000000000000000000000000000..bae7a817a6b6f20f09dd33ac3d40329d2d69914f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01076.java @@ -0,0 +1,138 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01076") +public class BenchmarkTest01076 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01076") != null) { + param = request.getHeader("BenchmarkTest01076"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + double stuff = java.security.SecureRandom.getInstance("SHA1PRNG").nextGaussian(); + String rememberMeKey = + Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "SafeGayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextGaussian() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextGaussian() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01077.java b/OWASP DATASET/BenchmarkTest01077.java new file mode 100644 index 0000000000000000000000000000000000000000..456dba17fce6b93fd74106d4f132282c6926b877 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01077.java @@ -0,0 +1,123 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01077") +public class BenchmarkTest01077 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01077") != null) { + param = request.getHeader("BenchmarkTest01077"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + int randNumber = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "SafeInga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt(int) - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt(int) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01078.java b/OWASP DATASET/BenchmarkTest01078.java new file mode 100644 index 0000000000000000000000000000000000000000..f802b5a93c68aca3cca94aef971c48161086c1c8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01078.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01078") +public class BenchmarkTest01078 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01078") != null) { + param = request.getHeader("BenchmarkTest01078"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + int randNumber = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "SafeInga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt(int) - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt(int) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz97831 = new StringBuilder(param); + String bar = sbxyz97831.append("_SafeStuff").toString(); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01079.java b/OWASP DATASET/BenchmarkTest01079.java new file mode 100644 index 0000000000000000000000000000000000000000..de7e540f921b45d7474704e654ac5151e22d2b4d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01079.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01079") +public class BenchmarkTest01079 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01079") != null) { + param = request.getHeader("BenchmarkTest01079"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + long l = java.security.SecureRandom.getInstance("SHA1PRNG").nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "SafeLogan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextLong() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextLong() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01080.java b/OWASP DATASET/BenchmarkTest01080.java new file mode 100644 index 0000000000000000000000000000000000000000..ed85ea3f34a818fe05b29c6d629cdaafe7ae2fc9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01080.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01080") +public class BenchmarkTest01080 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01080") != null) { + param = request.getHeader("BenchmarkTest01080"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String^,java.lang.Object) + request.getSession().putValue(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: 10340 saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01081.java b/OWASP DATASET/BenchmarkTest01081.java new file mode 100644 index 0000000000000000000000000000000000000000..5c226dae29ab5ca03b333bc7ff9cdf6f409b619f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01081.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01081") +public class BenchmarkTest01081 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01081") != null) { + param = request.getHeader("BenchmarkTest01081"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String^,java.lang.Object) + request.getSession().setAttribute(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: '10340' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz55141 = new StringBuilder(param); + String bar = sbxyz55141.append("_SafeStuff").toString(); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01082.java b/OWASP DATASET/BenchmarkTest01082.java new file mode 100644 index 0000000000000000000000000000000000000000..63eb520007c53213ed79662aa3bcd0107d7cedc2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01082.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01082") +public class BenchmarkTest01082 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01082") != null) { + param = request.getHeader("BenchmarkTest01082"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String^,java.lang.Object) + request.getSession().setAttribute(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: '10340' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01083.java b/OWASP DATASET/BenchmarkTest01083.java new file mode 100644 index 0000000000000000000000000000000000000000..8c35a3c0f423eac42ffe5f27eecf6be895a408c6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01083.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01083") +public class BenchmarkTest01083 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01083") != null) { + param = request.getHeader("BenchmarkTest01083"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01084.java b/OWASP DATASET/BenchmarkTest01084.java new file mode 100644 index 0000000000000000000000000000000000000000..39bc262d468f8fc4abd82bb81bfa8d5431f55f57 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01084.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01084") +public class BenchmarkTest01084 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01084") != null) { + param = request.getHeader("BenchmarkTest01084"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, new String[] {"Column1", "Column2"}); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01085.java b/OWASP DATASET/BenchmarkTest01085.java new file mode 100644 index 0000000000000000000000000000000000000000..45313dc2d8aceb187898de3c977264a5410aac2b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01085.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01085") +public class BenchmarkTest01085 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01085") != null) { + param = request.getHeader("BenchmarkTest01085"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.execute(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring execute method doesn't return results."); + + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01086.java b/OWASP DATASET/BenchmarkTest01086.java new file mode 100644 index 0000000000000000000000000000000000000000..37cc237de21c929ceefef224613bc78d03db1b00 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01086.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01086") +public class BenchmarkTest01086 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01086") != null) { + param = request.getHeader("BenchmarkTest01086"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.execute(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring execute method doesn't return results."); + + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01087.java b/OWASP DATASET/BenchmarkTest01087.java new file mode 100644 index 0000000000000000000000000000000000000000..2dd40979a6ecff9fad30638c37580c8756e535d4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01087.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01087") +public class BenchmarkTest01087 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01087") != null) { + param = request.getHeader("BenchmarkTest01087"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // int results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForInt(sql); + Integer results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Integer.class); + response.getWriter().println("Your results are: " + results); + // System.out.println("Your results are: " + results); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01088.java b/OWASP DATASET/BenchmarkTest01088.java new file mode 100644 index 0000000000000000000000000000000000000000..14ff34be7a32bc04e0b03c37f0999d9baedb971c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01088.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01088") +public class BenchmarkTest01088 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01088") != null) { + param = request.getHeader("BenchmarkTest01088"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // Long results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForLong(sql); + Long results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Long.class); + response.getWriter().println("Your results are: " + String.valueOf(results)); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01089.java b/OWASP DATASET/BenchmarkTest01089.java new file mode 100644 index 0000000000000000000000000000000000000000..e9a7614edd8b2d0c720f23b7d93dd0fed5ea7c84 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01089.java @@ -0,0 +1,93 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01089") +public class BenchmarkTest01089 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01089") != null) { + param = request.getHeader("BenchmarkTest01089"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = + "SELECT TOP 1 USERNAME from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + Object results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, new Object[] {}, String.class); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(results.toString())); + // System.out.println(results.toString()); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map11607 = new java.util.HashMap(); + map11607.put("keyA-11607", "a_Value"); // put some stuff in the collection + map11607.put("keyB-11607", param); // put it in a collection + map11607.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map11607.get("keyB-11607"); // get it back out + bar = (String) map11607.get("keyA-11607"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01090.java b/OWASP DATASET/BenchmarkTest01090.java new file mode 100644 index 0000000000000000000000000000000000000000..d32c576efb5ada406684b7fd5942bd6ca2c6244c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01090.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01090") +public class BenchmarkTest01090 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01090") != null) { + param = request.getHeader("BenchmarkTest01090"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.addBatch(sql); + int[] counts = statement.executeBatch(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(sql, counts, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map12212 = new java.util.HashMap(); + map12212.put("keyA-12212", "a-Value"); // put some stuff in the collection + map12212.put("keyB-12212", param); // put it in a collection + map12212.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map12212.get("keyB-12212"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01091.java b/OWASP DATASET/BenchmarkTest01091.java new file mode 100644 index 0000000000000000000000000000000000000000..742b793533bfa8cafc7a750b53230ab193abdcc9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01091.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01091") +public class BenchmarkTest01091 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01091") != null) { + param = request.getHeader("BenchmarkTest01091"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01092.java b/OWASP DATASET/BenchmarkTest01092.java new file mode 100644 index 0000000000000000000000000000000000000000..ed043e74d73dbcfb9fa27a067fa62a809ecd93e6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01092.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01092") +public class BenchmarkTest01092 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01092") != null) { + param = request.getHeader("BenchmarkTest01092"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01093.java b/OWASP DATASET/BenchmarkTest01093.java new file mode 100644 index 0000000000000000000000000000000000000000..f73991dd7bde0c4e17f01e03bf5de378ad5c0c58 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01093.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01093") +public class BenchmarkTest01093 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01093") != null) { + param = request.getHeader("BenchmarkTest01093"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map18142 = new java.util.HashMap(); + map18142.put("keyA-18142", "a-Value"); // put some stuff in the collection + map18142.put("keyB-18142", param); // put it in a collection + map18142.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map18142.get("keyB-18142"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01094.java b/OWASP DATASET/BenchmarkTest01094.java new file mode 100644 index 0000000000000000000000000000000000000000..dd9b0be9f25e29893a9e30e1bc2692c1602879a7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01094.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01094") +public class BenchmarkTest01094 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01094") != null) { + param = request.getHeader("BenchmarkTest01094"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new String[] {"username", "password"}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01095.java b/OWASP DATASET/BenchmarkTest01095.java new file mode 100644 index 0000000000000000000000000000000000000000..82b0497b36cd4db362c4f12c2a628d137536f6e5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01095.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01095") +public class BenchmarkTest01095 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01095") != null) { + param = request.getHeader("BenchmarkTest01095"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new String[] {"username", "password"}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01096.java b/OWASP DATASET/BenchmarkTest01096.java new file mode 100644 index 0000000000000000000000000000000000000000..04df2c0a13e27b4a65c9dacb35d44a78abf37512 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01096.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01096") +public class BenchmarkTest01096 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01096") != null) { + param = request.getHeader("BenchmarkTest01096"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01097.java b/OWASP DATASET/BenchmarkTest01097.java new file mode 100644 index 0000000000000000000000000000000000000000..a7b174be36e200c1b4fd6b9a202c6f164920564f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01097.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01097") +public class BenchmarkTest01097 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01097") != null) { + param = request.getHeader("BenchmarkTest01097"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01098.java b/OWASP DATASET/BenchmarkTest01098.java new file mode 100644 index 0000000000000000000000000000000000000000..7a6c3c44c775324e759adb221e0763ba1f597ef6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01098.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01098") +public class BenchmarkTest01098 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01098") != null) { + param = request.getHeader("BenchmarkTest01098"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01099.java b/OWASP DATASET/BenchmarkTest01099.java new file mode 100644 index 0000000000000000000000000000000000000000..eac78a3fb079b636e5ec23402b18aa48b44a5d25 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01099.java @@ -0,0 +1,180 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01099") +public class BenchmarkTest01099 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "DES/CBC/PKCS5PADDING", java.security.Security.getProvider("SunJCE")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map30744 = new java.util.HashMap(); + map30744.put("keyA-30744", "a_Value"); // put some stuff in the collection + map30744.put("keyB-30744", param); // put it in a collection + map30744.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map30744.get("keyB-30744"); // get it back out + bar = (String) map30744.get("keyA-30744"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01100.java b/OWASP DATASET/BenchmarkTest01100.java new file mode 100644 index 0000000000000000000000000000000000000000..ab997b2ee8d70da999f288cf0f8b0cad284f841d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01100.java @@ -0,0 +1,141 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01100") +public class BenchmarkTest01100 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = org.owasp.benchmark.helpers.Utils.getCipher(); + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz90035 = new StringBuilder(param); + bar = + sbxyz90035 + .replace(param.length() - "Z".length(), param.length(), "Z") + .toString(); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01101.java b/OWASP DATASET/BenchmarkTest01101.java new file mode 100644 index 0000000000000000000000000000000000000000..6841d7c8db455e7e40d2c5ebf6b677c48dff70a2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01101.java @@ -0,0 +1,134 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01101") +public class BenchmarkTest01101 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = org.owasp.benchmark.helpers.Utils.getCipher(); + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01102.java b/OWASP DATASET/BenchmarkTest01102.java new file mode 100644 index 0000000000000000000000000000000000000000..d22c06ddd7d373083144d05a1bdf39bc2ea23571 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01102.java @@ -0,0 +1,149 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01102") +public class BenchmarkTest01102 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map10086 = new java.util.HashMap(); + map10086.put("keyA-10086", "a-Value"); // put some stuff in the collection + map10086.put("keyB-10086", param); // put it in a collection + map10086.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map10086.get("keyB-10086"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01103.java b/OWASP DATASET/BenchmarkTest01103.java new file mode 100644 index 0000000000000000000000000000000000000000..994f65eb68001bcd651412d3c28b5e8c567be0b8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01103.java @@ -0,0 +1,163 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01103") +public class BenchmarkTest01103 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01104.java b/OWASP DATASET/BenchmarkTest01104.java new file mode 100644 index 0000000000000000000000000000000000000000..79b0ed2d9027d2ffc01eae5af48af372a16f0a4e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01104.java @@ -0,0 +1,155 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01104") +public class BenchmarkTest01104 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "AES/CCM/NoPadding", java.security.Security.getProvider("BC")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01105.java b/OWASP DATASET/BenchmarkTest01105.java new file mode 100644 index 0000000000000000000000000000000000000000..6a33470a28f80a71276191b2d1edce8197e51797 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01105.java @@ -0,0 +1,135 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01105") +public class BenchmarkTest01105 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01106.java b/OWASP DATASET/BenchmarkTest01106.java new file mode 100644 index 0000000000000000000000000000000000000000..1857d3595ce051c317d7ecd7d9f3b3b74ea2c080 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01106.java @@ -0,0 +1,135 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01106") +public class BenchmarkTest01106 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01107.java b/OWASP DATASET/BenchmarkTest01107.java new file mode 100644 index 0000000000000000000000000000000000000000..41a8570d608a80c7d2c5d608bdc7087f1f10af09 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01107.java @@ -0,0 +1,140 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01107") +public class BenchmarkTest01107 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01108.java b/OWASP DATASET/BenchmarkTest01108.java new file mode 100644 index 0000000000000000000000000000000000000000..abadd33199ac34dec7aee3d44e9b066c763f3380 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01108.java @@ -0,0 +1,152 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01108") +public class BenchmarkTest01108 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + // java.security.SecureRandom random = new java.security.SecureRandom(); + // byte[] iv = random.generateSeed(16); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg2", "AES/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01109.java b/OWASP DATASET/BenchmarkTest01109.java new file mode 100644 index 0000000000000000000000000000000000000000..c3b3a4aa98c310451f7aa96176497e842aebdf27 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01109.java @@ -0,0 +1,111 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01109") +public class BenchmarkTest01109 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + java.io.File fileTarget = new java.io.File(bar, "/Test.txt"); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a87030 = param; // assign + StringBuilder b87030 = new StringBuilder(a87030); // stick in stringbuilder + b87030.append(" SafeStuff"); // append some safe content + b87030.replace( + b87030.length() - "Chars".length(), + b87030.length(), + "Chars"); // replace some of the end content + java.util.HashMap map87030 = new java.util.HashMap(); + map87030.put("key87030", b87030.toString()); // put in a collection + String c87030 = (String) map87030.get("key87030"); // get it back out + String d87030 = c87030.substring(0, c87030.length() - 1); // extract most of it + String e87030 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d87030.getBytes()))); // B64 encode and decode it + String f87030 = e87030.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g87030 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g87030); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01110.java b/OWASP DATASET/BenchmarkTest01110.java new file mode 100644 index 0000000000000000000000000000000000000000..e13828e1fb96e949453077f5d4c3ace5fc867070 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01110.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01110") +public class BenchmarkTest01110 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + // FILE URIs are tricky because they are different between Mac and Windows because of lack + // of standardization. + // Mac requires an extra slash for some reason. + String startURIslashes = ""; + if (System.getProperty("os.name").indexOf("Windows") != -1) + if (System.getProperty("os.name").indexOf("Windows") != -1) startURIslashes = "/"; + else startURIslashes = "//"; + + try { + java.net.URI fileURI = + new java.net.URI( + "file:" + + startURIslashes + + org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + .replace('\\', '/') + .replace(' ', '_') + + bar); + java.io.File fileTarget = new java.io.File(fileURI); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } catch (java.net.URISyntaxException e) { + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01111.java b/OWASP DATASET/BenchmarkTest01111.java new file mode 100644 index 0000000000000000000000000000000000000000..92cb3b991043d78ce50e9e81ff8a7efba023cae1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01111.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01111") +public class BenchmarkTest01111 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(fileName); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01112.java b/OWASP DATASET/BenchmarkTest01112.java new file mode 100644 index 0000000000000000000000000000000000000000..83ef692936e1cd189f461c150bb2f4531bfdf7bf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01112.java @@ -0,0 +1,122 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01112") +public class BenchmarkTest01112 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(fileName); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01113.java b/OWASP DATASET/BenchmarkTest01113.java new file mode 100644 index 0000000000000000000000000000000000000000..ba36392041aa7aa97286163a26f68c2987a21592 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01113.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01113") +public class BenchmarkTest01113 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName), false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map50384 = new java.util.HashMap(); + map50384.put("keyA-50384", "a_Value"); // put some stuff in the collection + map50384.put("keyB-50384", param); // put it in a collection + map50384.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map50384.get("keyB-50384"); // get it back out + bar = (String) map50384.get("keyA-50384"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01114.java b/OWASP DATASET/BenchmarkTest01114.java new file mode 100644 index 0000000000000000000000000000000000000000..b696e8e873044bb7c84f69961d384be5594af848 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01114.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01114") +public class BenchmarkTest01114 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName), false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a97099 = param; // assign + StringBuilder b97099 = new StringBuilder(a97099); // stick in stringbuilder + b97099.append(" SafeStuff"); // append some safe content + b97099.replace( + b97099.length() - "Chars".length(), + b97099.length(), + "Chars"); // replace some of the end content + java.util.HashMap map97099 = new java.util.HashMap(); + map97099.put("key97099", b97099.toString()); // put in a collection + String c97099 = (String) map97099.get("key97099"); // get it back out + String d97099 = c97099.substring(0, c97099.length() - 1); // extract most of it + String e97099 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d97099.getBytes()))); // B64 encode and decode it + String f97099 = e97099.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g97099 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g97099); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01115.java b/OWASP DATASET/BenchmarkTest01115.java new file mode 100644 index 0000000000000000000000000000000000000000..3a348c1ccdc66aa748f74a3b784f66ed1399fc68 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01115.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01115") +public class BenchmarkTest01115 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName)); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a43762 = param; // assign + StringBuilder b43762 = new StringBuilder(a43762); // stick in stringbuilder + b43762.append(" SafeStuff"); // append some safe content + b43762.replace( + b43762.length() - "Chars".length(), + b43762.length(), + "Chars"); // replace some of the end content + java.util.HashMap map43762 = new java.util.HashMap(); + map43762.put("key43762", b43762.toString()); // put in a collection + String c43762 = (String) map43762.get("key43762"); // get it back out + String d43762 = c43762.substring(0, c43762.length() - 1); // extract most of it + String e43762 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d43762.getBytes()))); // B64 encode and decode it + String f43762 = e43762.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g43762 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g43762); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01116.java b/OWASP DATASET/BenchmarkTest01116.java new file mode 100644 index 0000000000000000000000000000000000000000..f9904a651c3f982f167552f60f94869312563aa1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01116.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01116") +public class BenchmarkTest01116 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + try ( + // Create the file first so the test won't throw an exception if it doesn't exist. + // Note: Don't actually do this because this method signature could cause a tool to find + // THIS file constructor + // as a vuln, rather than the File signature we are trying to actually test. + // If necessary, just run the benchmark twice. The 1st run should create all the necessary + // files. + // new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar).createNewFile(); + + java.io.FileOutputStream fos = + new java.io.FileOutputStream(new java.io.FileInputStream(fileName).getFD()); ) { + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01117.java b/OWASP DATASET/BenchmarkTest01117.java new file mode 100644 index 0000000000000000000000000000000000000000..dc25a45f6e15ce35fa91b7726a8e4c70fdaefbaf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01117.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01117") +public class BenchmarkTest01117 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + try ( + // Create the file first so the test won't throw an exception if it doesn't exist. + // Note: Don't actually do this because this method signature could cause a tool to find + // THIS file constructor + // as a vuln, rather than the File signature we are trying to actually test. + // If necessary, just run the benchmark twice. The 1st run should create all the necessary + // files. + // new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar).createNewFile(); + + java.io.FileOutputStream fos = + new java.io.FileOutputStream(new java.io.FileInputStream(fileName).getFD()); ) { + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01118.java b/OWASP DATASET/BenchmarkTest01118.java new file mode 100644 index 0000000000000000000000000000000000000000..1209b84a73bbf5664f5bf64b812566b760e6e993 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01118.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01118") +public class BenchmarkTest01118 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + java.io.InputStream is = null; + + try { + java.nio.file.Path path = java.nio.file.Paths.get(fileName); + is = java.nio.file.Files.newInputStream(path, java.nio.file.StandardOpenOption.READ); + byte[] b = new byte[1000]; + int size = is.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + is.close(); + } catch (Exception e) { + System.out.println("Couldn't open InputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting InputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (is != null) { + try { + is.close(); + is = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map63904 = new java.util.HashMap(); + map63904.put("keyA-63904", "a_Value"); // put some stuff in the collection + map63904.put("keyB-63904", param); // put it in a collection + map63904.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map63904.get("keyB-63904"); // get it back out + bar = (String) map63904.get("keyA-63904"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01119.java b/OWASP DATASET/BenchmarkTest01119.java new file mode 100644 index 0000000000000000000000000000000000000000..c0b5e4a2cc1b9ec9c726235182dab5a0fd65cbe3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01119.java @@ -0,0 +1,142 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01119") +public class BenchmarkTest01119 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + double value = java.lang.Math.random(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Doug"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + response.getWriter().println("Weak Randomness Test java.lang.Math.random() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01120.java b/OWASP DATASET/BenchmarkTest01120.java new file mode 100644 index 0000000000000000000000000000000000000000..788b425ba3340943e0a79299b20292a7e79d4d7d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01120.java @@ -0,0 +1,156 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01120") +public class BenchmarkTest01120 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("sha-384", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("sha-384", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a99915 = param; // assign + StringBuilder b99915 = new StringBuilder(a99915); // stick in stringbuilder + b99915.append(" SafeStuff"); // append some safe content + b99915.replace( + b99915.length() - "Chars".length(), + b99915.length(), + "Chars"); // replace some of the end content + java.util.HashMap map99915 = new java.util.HashMap(); + map99915.put("key99915", b99915.toString()); // put in a collection + String c99915 = (String) map99915.get("key99915"); // get it back out + String d99915 = c99915.substring(0, c99915.length() - 1); // extract most of it + String e99915 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d99915.getBytes()))); // B64 encode and decode it + String f99915 = e99915.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f99915); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01121.java b/OWASP DATASET/BenchmarkTest01121.java new file mode 100644 index 0000000000000000000000000000000000000000..8df9c5bfc5bf96dbf675ed56720be177fa0cc0de --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01121.java @@ -0,0 +1,137 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01121") +public class BenchmarkTest01121 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("sha-384", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("sha-384", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz22801 = new StringBuilder(param); + String bar = sbxyz22801.append("_SafeStuff").toString(); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01122.java b/OWASP DATASET/BenchmarkTest01122.java new file mode 100644 index 0000000000000000000000000000000000000000..8b1c738d932604a7516684096d5e11bff23c1625 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01122.java @@ -0,0 +1,155 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01122") +public class BenchmarkTest01122 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("sha-384", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("sha-384", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01123.java b/OWASP DATASET/BenchmarkTest01123.java new file mode 100644 index 0000000000000000000000000000000000000000..15992f6c66837363b67ff8bcb2218237ac325cb2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01123.java @@ -0,0 +1,135 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01123") +public class BenchmarkTest01123 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01124.java b/OWASP DATASET/BenchmarkTest01124.java new file mode 100644 index 0000000000000000000000000000000000000000..a9beaeafa567f92075a77f51b63dd480729b5257 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01124.java @@ -0,0 +1,133 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01124") +public class BenchmarkTest01124 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map74702 = new java.util.HashMap(); + map74702.put("keyA-74702", "a_Value"); // put some stuff in the collection + map74702.put("keyB-74702", param); // put it in a collection + map74702.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map74702.get("keyB-74702"); // get it back out + bar = (String) map74702.get("keyA-74702"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01125.java b/OWASP DATASET/BenchmarkTest01125.java new file mode 100644 index 0000000000000000000000000000000000000000..21bb95d113d3ddc1e0277a38271873fc368797d7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01125.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01125") +public class BenchmarkTest01125 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01126.java b/OWASP DATASET/BenchmarkTest01126.java new file mode 100644 index 0000000000000000000000000000000000000000..27fb90364f6dcf2f92ed6f290b70b85f4cfe6b41 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01126.java @@ -0,0 +1,132 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01126") +public class BenchmarkTest01126 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01127.java b/OWASP DATASET/BenchmarkTest01127.java new file mode 100644 index 0000000000000000000000000000000000000000..2f6aa0b6fba0946a8888af98fe9d98e1a7318684 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01127.java @@ -0,0 +1,128 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01127") +public class BenchmarkTest01127 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + double value = new java.util.Random().nextDouble(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Donna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextDouble() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01128.java b/OWASP DATASET/BenchmarkTest01128.java new file mode 100644 index 0000000000000000000000000000000000000000..4f6f5c5231af8e421908e00f443a2ac204858434 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01128.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01128") +public class BenchmarkTest01128 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + double stuff = new java.util.Random().nextGaussian(); + String rememberMeKey = Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "Gayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter() + .println("Weak Randomness Test java.util.Random.nextGaussian() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz90224 = new StringBuilder(param); + bar = + sbxyz90224 + .replace(param.length() - "Z".length(), param.length(), "Z") + .toString(); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01129.java b/OWASP DATASET/BenchmarkTest01129.java new file mode 100644 index 0000000000000000000000000000000000000000..8e6f60544adcbad056021f666da31c5705ac519e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01129.java @@ -0,0 +1,127 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01129") +public class BenchmarkTest01129 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + int randNumber = new java.util.Random().nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "Inga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt(int) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01130.java b/OWASP DATASET/BenchmarkTest01130.java new file mode 100644 index 0000000000000000000000000000000000000000..a8e858743ea785cbaec52e4e5b4affe6ea9c507e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01130.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01130") +public class BenchmarkTest01130 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01131.java b/OWASP DATASET/BenchmarkTest01131.java new file mode 100644 index 0000000000000000000000000000000000000000..e1abf7345352cd43bc753b1a1853376a72287340 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01131.java @@ -0,0 +1,125 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01131") +public class BenchmarkTest01131 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01132.java b/OWASP DATASET/BenchmarkTest01132.java new file mode 100644 index 0000000000000000000000000000000000000000..19d1cf25d8a703009c179e682175416f0ddd219e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01132.java @@ -0,0 +1,141 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01132") +public class BenchmarkTest01132 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01133.java b/OWASP DATASET/BenchmarkTest01133.java new file mode 100644 index 0000000000000000000000000000000000000000..5cd6a82d9adadcb2976e326003d56ea073af3b65 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01133.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01133") +public class BenchmarkTest01133 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01134.java b/OWASP DATASET/BenchmarkTest01134.java new file mode 100644 index 0000000000000000000000000000000000000000..d2034ebfce58952a4576b40c925f9462b2c75f7e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01134.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest01134") +public class BenchmarkTest01134 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map9728 = new java.util.HashMap(); + map9728.put("keyA-9728", "a-Value"); // put some stuff in the collection + map9728.put("keyB-9728", param); // put it in a collection + map9728.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map9728.get("keyB-9728"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01135.java b/OWASP DATASET/BenchmarkTest01135.java new file mode 100644 index 0000000000000000000000000000000000000000..d0997ff21d9dd8fc71cb9cd6713ec18996a0c350 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01135.java @@ -0,0 +1,140 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01135") +public class BenchmarkTest01135 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + getNextNumber(numGen, randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeBystander"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + void getNextNumber(java.util.Random generator, byte[] barray) { + generator.nextBytes(barray); + } + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01136.java b/OWASP DATASET/BenchmarkTest01136.java new file mode 100644 index 0000000000000000000000000000000000000000..63fbc6b1065bccf0fd13c9d451472e45413b801f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01136.java @@ -0,0 +1,158 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01136") +public class BenchmarkTest01136 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a58606 = param; // assign + StringBuilder b58606 = new StringBuilder(a58606); // stick in stringbuilder + b58606.append(" SafeStuff"); // append some safe content + b58606.replace( + b58606.length() - "Chars".length(), + b58606.length(), + "Chars"); // replace some of the end content + java.util.HashMap map58606 = new java.util.HashMap(); + map58606.put("key58606", b58606.toString()); // put in a collection + String c58606 = (String) map58606.get("key58606"); // get it back out + String d58606 = c58606.substring(0, c58606.length() - 1); // extract most of it + String e58606 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d58606.getBytes()))); // B64 encode and decode it + String f58606 = e58606.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g58606 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g58606); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01137.java b/OWASP DATASET/BenchmarkTest01137.java new file mode 100644 index 0000000000000000000000000000000000000000..fd51863df6abc28f707572d97e555e1f4abc9903 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01137.java @@ -0,0 +1,132 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01137") +public class BenchmarkTest01137 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz8314 = new StringBuilder(param); + String bar = sbxyz8314.append("_SafeStuff").toString(); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01138.java b/OWASP DATASET/BenchmarkTest01138.java new file mode 100644 index 0000000000000000000000000000000000000000..6a1fc63c940708388154ad91c8290e5dc907b553 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01138.java @@ -0,0 +1,136 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01138") +public class BenchmarkTest01138 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + try { + float rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextFloat(); + String rememberMeKey = + Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeFloyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextFloat() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextFloat() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz47470 = new StringBuilder(param); + bar = + sbxyz47470 + .replace(param.length() - "Z".length(), param.length(), "Z") + .toString(); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01139.java b/OWASP DATASET/BenchmarkTest01139.java new file mode 100644 index 0000000000000000000000000000000000000000..40737e19175082b65f8e5b905001eb68ec84d9c8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01139.java @@ -0,0 +1,136 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01139") +public class BenchmarkTest01139 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + try { + double stuff = java.security.SecureRandom.getInstance("SHA1PRNG").nextGaussian(); + String rememberMeKey = + Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "SafeGayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextGaussian() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextGaussian() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz40917 = new StringBuilder(param); + bar = + sbxyz40917 + .replace(param.length() - "Z".length(), param.length(), "Z") + .toString(); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01140.java b/OWASP DATASET/BenchmarkTest01140.java new file mode 100644 index 0000000000000000000000000000000000000000..e48a1dbf620f76631f7b15b92e4c640d7ad61a18 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01140.java @@ -0,0 +1,149 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01140") +public class BenchmarkTest01140 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + try { + long l = java.security.SecureRandom.getInstance("SHA1PRNG").nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "SafeLogan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextLong() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextLong() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a25760 = param; // assign + StringBuilder b25760 = new StringBuilder(a25760); // stick in stringbuilder + b25760.append(" SafeStuff"); // append some safe content + b25760.replace( + b25760.length() - "Chars".length(), + b25760.length(), + "Chars"); // replace some of the end content + java.util.HashMap map25760 = new java.util.HashMap(); + map25760.put("key25760", b25760.toString()); // put in a collection + String c25760 = (String) map25760.get("key25760"); // get it back out + String d25760 = c25760.substring(0, c25760.length() - 1); // extract most of it + String e25760 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d25760.getBytes()))); // B64 encode and decode it + String f25760 = e25760.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g25760 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g25760); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01141.java b/OWASP DATASET/BenchmarkTest01141.java new file mode 100644 index 0000000000000000000000000000000000000000..bc54bd91babace6bcfa6c7a7d3477590472c5827 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01141.java @@ -0,0 +1,135 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01141") +public class BenchmarkTest01141 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + try { + long l = java.security.SecureRandom.getInstance("SHA1PRNG").nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "SafeLogan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextLong() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextLong() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz2940 = new StringBuilder(param); + bar = + sbxyz2940 + .replace(param.length() - "Z".length(), param.length(), "Z") + .toString(); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01142.java b/OWASP DATASET/BenchmarkTest01142.java new file mode 100644 index 0000000000000000000000000000000000000000..749b2312fcdd787e78a5d5b9070a69b0a4ecfbd2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01142.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01142") +public class BenchmarkTest01142 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01143.java b/OWASP DATASET/BenchmarkTest01143.java new file mode 100644 index 0000000000000000000000000000000000000000..85bfcbef88bd0fab883e97cfa7329a3ef8313bc1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01143.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01143") +public class BenchmarkTest01143 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz70712 = new StringBuilder(param); + String bar = sbxyz70712.append("_SafeStuff").toString(); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01144.java b/OWASP DATASET/BenchmarkTest01144.java new file mode 100644 index 0000000000000000000000000000000000000000..7402fce99de2d93c13070596256ec8ce5319cac8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01144.java @@ -0,0 +1,93 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01144") +public class BenchmarkTest01144 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01145.java b/OWASP DATASET/BenchmarkTest01145.java new file mode 100644 index 0000000000000000000000000000000000000000..d5f1c56669c5501cc7723650bb57083c32ae3af0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01145.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01145") +public class BenchmarkTest01145 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01146.java b/OWASP DATASET/BenchmarkTest01146.java new file mode 100644 index 0000000000000000000000000000000000000000..f9059723732d1e23c3a212177f834e9502309947 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01146.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01146") +public class BenchmarkTest01146 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01147.java b/OWASP DATASET/BenchmarkTest01147.java new file mode 100644 index 0000000000000000000000000000000000000000..9fdb38dee8534ce34e5ea0a643657d61cad2adc5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01147.java @@ -0,0 +1,174 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01147") +public class BenchmarkTest01147 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01147"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz71288 = new StringBuilder(param); + bar = + sbxyz71288 + .replace(param.length() - "Z".length(), param.length(), "Z") + .toString(); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01148.java b/OWASP DATASET/BenchmarkTest01148.java new file mode 100644 index 0000000000000000000000000000000000000000..91a5223f7618db0964b75561bbd3a4055397f154 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01148.java @@ -0,0 +1,175 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01148") +public class BenchmarkTest01148 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01148"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01149.java b/OWASP DATASET/BenchmarkTest01149.java new file mode 100644 index 0000000000000000000000000000000000000000..0a96d7db708bdb744e0590f085df97d6c0ad4560 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01149.java @@ -0,0 +1,189 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01149") +public class BenchmarkTest01149 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01149"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01150.java b/OWASP DATASET/BenchmarkTest01150.java new file mode 100644 index 0000000000000000000000000000000000000000..786968376efa91c7ba4e9edfba4d453e6575404d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01150.java @@ -0,0 +1,146 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01150") +public class BenchmarkTest01150 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01150"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01151.java b/OWASP DATASET/BenchmarkTest01151.java new file mode 100644 index 0000000000000000000000000000000000000000..c056f4be4884aee24da2124eb576f05d6741d596 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01151.java @@ -0,0 +1,128 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01151") +public class BenchmarkTest01151 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01151"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "AES/CCM/NoPadding", java.security.Security.getProvider("BC")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01152.java b/OWASP DATASET/BenchmarkTest01152.java new file mode 100644 index 0000000000000000000000000000000000000000..9b7e57532b395fe550cc47b7b22ad187ca904495 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01152.java @@ -0,0 +1,133 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01152") +public class BenchmarkTest01152 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01152"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "AES/CCM/NoPadding", java.security.Security.getProvider("BC")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01153.java b/OWASP DATASET/BenchmarkTest01153.java new file mode 100644 index 0000000000000000000000000000000000000000..cdea093b1e249101baed0b7384d78576d6a86920 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01153.java @@ -0,0 +1,158 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01153") +public class BenchmarkTest01153 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01153"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + // java.security.SecureRandom random = new java.security.SecureRandom(); + // byte[] iv = random.generateSeed(16); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg2", "AES/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a2387 = param; // assign + StringBuilder b2387 = new StringBuilder(a2387); // stick in stringbuilder + b2387.append(" SafeStuff"); // append some safe content + b2387.replace( + b2387.length() - "Chars".length(), + b2387.length(), + "Chars"); // replace some of the end content + java.util.HashMap map2387 = new java.util.HashMap(); + map2387.put("key2387", b2387.toString()); // put in a collection + String c2387 = (String) map2387.get("key2387"); // get it back out + String d2387 = c2387.substring(0, c2387.length() - 1); // extract most of it + String e2387 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d2387.getBytes()))); // B64 encode and decode it + String f2387 = e2387.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g2387 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g2387); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01154.java b/OWASP DATASET/BenchmarkTest01154.java new file mode 100644 index 0000000000000000000000000000000000000000..1ef4bfffe73d38f0854ffef83ebc54d9f5e7cd22 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01154.java @@ -0,0 +1,135 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest01154") +public class BenchmarkTest01154 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01154"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + javax.naming.directory.DirContext ctx = ads.getDirContext(); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + bar + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + // System.out.println("Filter " + filter); + boolean found = false; + javax.naming.NamingEnumeration results = + ctx.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01155.java b/OWASP DATASET/BenchmarkTest01155.java new file mode 100644 index 0000000000000000000000000000000000000000..a1f290241296f892843e0822fbaf3bf2ba23e3db --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01155.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01155") +public class BenchmarkTest01155 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01155"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + java.io.File fileTarget = new java.io.File(bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01156.java b/OWASP DATASET/BenchmarkTest01156.java new file mode 100644 index 0000000000000000000000000000000000000000..fa51554c958592d81fe43d65e001b072c282b658 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01156.java @@ -0,0 +1,107 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01156") +public class BenchmarkTest01156 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01156"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // FILE URIs are tricky because they are different between Mac and Windows because of lack + // of standardization. + // Mac requires an extra slash for some reason. + String startURIslashes = ""; + if (System.getProperty("os.name").indexOf("Windows") != -1) + if (System.getProperty("os.name").indexOf("Windows") != -1) startURIslashes = "/"; + else startURIslashes = "//"; + + try { + java.net.URI fileURI = + new java.net.URI( + "file:" + + startURIslashes + + org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + .replace('\\', '/') + .replace(' ', '_') + + bar); + java.io.File fileTarget = new java.io.File(fileURI); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } catch (java.net.URISyntaxException e) { + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map55476 = new java.util.HashMap(); + map55476.put("keyA-55476", "a-Value"); // put some stuff in the collection + map55476.put("keyB-55476", param); // put it in a collection + map55476.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map55476.get("keyB-55476"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01157.java b/OWASP DATASET/BenchmarkTest01157.java new file mode 100644 index 0000000000000000000000000000000000000000..6fe7bf2e109bda1dc13df7ba6e29d2f9911acd2a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01157.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01157") +public class BenchmarkTest01157 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01157"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // FILE URIs are tricky because they are different between Mac and Windows because of lack + // of standardization. + // Mac requires an extra slash for some reason. + String startURIslashes = ""; + if (System.getProperty("os.name").indexOf("Windows") != -1) + if (System.getProperty("os.name").indexOf("Windows") != -1) startURIslashes = "/"; + else startURIslashes = "//"; + + try { + java.net.URI fileURI = + new java.net.URI( + "file:" + + startURIslashes + + org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + .replace('\\', '/') + .replace(' ', '_') + + bar); + java.io.File fileTarget = new java.io.File(fileURI); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } catch (java.net.URISyntaxException e) { + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01158.java b/OWASP DATASET/BenchmarkTest01158.java new file mode 100644 index 0000000000000000000000000000000000000000..e21ec0b496f792056c2adf74de6c5a11bf57aa63 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01158.java @@ -0,0 +1,105 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01158") +public class BenchmarkTest01158 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01158"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(fileName); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01159.java b/OWASP DATASET/BenchmarkTest01159.java new file mode 100644 index 0000000000000000000000000000000000000000..6fef40ca2f5a1ccea4b1884d31fe64dda7171935 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01159.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01159") +public class BenchmarkTest01159 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01159"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(fileName); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a54259 = param; // assign + StringBuilder b54259 = new StringBuilder(a54259); // stick in stringbuilder + b54259.append(" SafeStuff"); // append some safe content + b54259.replace( + b54259.length() - "Chars".length(), + b54259.length(), + "Chars"); // replace some of the end content + java.util.HashMap map54259 = new java.util.HashMap(); + map54259.put("key54259", b54259.toString()); // put in a collection + String c54259 = (String) map54259.get("key54259"); // get it back out + String d54259 = c54259.substring(0, c54259.length() - 1); // extract most of it + String e54259 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d54259.getBytes()))); // B64 encode and decode it + String f54259 = e54259.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g54259 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g54259); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01160.java b/OWASP DATASET/BenchmarkTest01160.java new file mode 100644 index 0000000000000000000000000000000000000000..78cdc16f89dfd6567b065d672c3d2f79fa77ccd3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01160.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01160") +public class BenchmarkTest01160 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01160"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName), false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01161.java b/OWASP DATASET/BenchmarkTest01161.java new file mode 100644 index 0000000000000000000000000000000000000000..007756fe6aeb35373fcb770cc606ff637f0c9ddd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01161.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01161") +public class BenchmarkTest01161 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01161"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName, false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01162.java b/OWASP DATASET/BenchmarkTest01162.java new file mode 100644 index 0000000000000000000000000000000000000000..92d5140fb5103e655bd270fd6abd9f09c6140e2f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01162.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01162") +public class BenchmarkTest01162 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01162"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + double value = java.lang.Math.random(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Doug"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + response.getWriter().println("Weak Randomness Test java.lang.Math.random() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map72162 = new java.util.HashMap(); + map72162.put("keyA-72162", "a_Value"); // put some stuff in the collection + map72162.put("keyB-72162", param); // put it in a collection + map72162.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map72162.get("keyB-72162"); // get it back out + bar = (String) map72162.get("keyA-72162"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01163.java b/OWASP DATASET/BenchmarkTest01163.java new file mode 100644 index 0000000000000000000000000000000000000000..c9aecb932600d5437d61da653ed62ed048bc1170 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01163.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01163") +public class BenchmarkTest01163 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01163"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + double value = java.lang.Math.random(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Doug"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + response.getWriter().println("Weak Randomness Test java.lang.Math.random() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01164.java b/OWASP DATASET/BenchmarkTest01164.java new file mode 100644 index 0000000000000000000000000000000000000000..ef2641b4e9b6e2181adc0f0889fcd7e0d5ed4977 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01164.java @@ -0,0 +1,135 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01164") +public class BenchmarkTest01164 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01164"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("sha-384", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("sha-384", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01165.java b/OWASP DATASET/BenchmarkTest01165.java new file mode 100644 index 0000000000000000000000000000000000000000..f0ce54a8a86f6a82d11edf2458e7b2f3edb8feaa --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01165.java @@ -0,0 +1,141 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01165") +public class BenchmarkTest01165 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01165"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a91034 = param; // assign + StringBuilder b91034 = new StringBuilder(a91034); // stick in stringbuilder + b91034.append(" SafeStuff"); // append some safe content + b91034.replace( + b91034.length() - "Chars".length(), + b91034.length(), + "Chars"); // replace some of the end content + java.util.HashMap map91034 = new java.util.HashMap(); + map91034.put("key91034", b91034.toString()); // put in a collection + String c91034 = (String) map91034.get("key91034"); // get it back out + String d91034 = c91034.substring(0, c91034.length() - 1); // extract most of it + String e91034 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d91034.getBytes()))); // B64 encode and decode it + String f91034 = e91034.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g91034 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g91034); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01166.java b/OWASP DATASET/BenchmarkTest01166.java new file mode 100644 index 0000000000000000000000000000000000000000..1870e695ed4561b10da6a9a7e5dbb9580d2d65df --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01166.java @@ -0,0 +1,127 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01166") +public class BenchmarkTest01166 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01166"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz52006 = new StringBuilder(param); + bar = + sbxyz52006 + .replace(param.length() - "Z".length(), param.length(), "Z") + .toString(); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01167.java b/OWASP DATASET/BenchmarkTest01167.java new file mode 100644 index 0000000000000000000000000000000000000000..2521fc5b8e2b1e60e7866354e646c221e4ce5153 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01167.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01167") +public class BenchmarkTest01167 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01167"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map70586 = new java.util.HashMap(); + map70586.put("keyA-70586", "a-Value"); // put some stuff in the collection + map70586.put("keyB-70586", param); // put it in a collection + map70586.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map70586.get("keyB-70586"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01168.java b/OWASP DATASET/BenchmarkTest01168.java new file mode 100644 index 0000000000000000000000000000000000000000..55f37e7aac0dafe3b973817000da01ed8da57024 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01168.java @@ -0,0 +1,138 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01168") +public class BenchmarkTest01168 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01168"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01169.java b/OWASP DATASET/BenchmarkTest01169.java new file mode 100644 index 0000000000000000000000000000000000000000..4530d133a60f1998216fb7107df3b0aa1a645afa --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01169.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01169") +public class BenchmarkTest01169 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01169"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01170.java b/OWASP DATASET/BenchmarkTest01170.java new file mode 100644 index 0000000000000000000000000000000000000000..6c2b0c0bf0acc825e2a0011f5aea3af0821061e5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01170.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01170") +public class BenchmarkTest01170 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01170"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01171.java b/OWASP DATASET/BenchmarkTest01171.java new file mode 100644 index 0000000000000000000000000000000000000000..ff1a002a02ac0c471563c4c4821cccf3961b60f1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01171.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01171") +public class BenchmarkTest01171 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(java.util.Locale.US, bar, obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz83647 = new StringBuilder(param); + bar = + sbxyz83647 + .replace(param.length() - "Z".length(), param.length(), "Z") + .toString(); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01172.java b/OWASP DATASET/BenchmarkTest01172.java new file mode 100644 index 0000000000000000000000000000000000000000..77d967e09bfb5aa9a67b1c26e7c9997303022dab --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01172.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01172") +public class BenchmarkTest01172 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().format("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map35084 = new java.util.HashMap(); + map35084.put("keyA-35084", "a-Value"); // put some stuff in the collection + map35084.put("keyB-35084", param); // put it in a collection + map35084.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map35084.get("keyB-35084"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01173.java b/OWASP DATASET/BenchmarkTest01173.java new file mode 100644 index 0000000000000000000000000000000000000000..105a919ff8eebcb2b2fbc274242e24d85eb987b2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01173.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01173") +public class BenchmarkTest01173 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01174.java b/OWASP DATASET/BenchmarkTest01174.java new file mode 100644 index 0000000000000000000000000000000000000000..b96d9dffc803e5e58f7d85c39babb0a817836e26 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01174.java @@ -0,0 +1,72 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01174") +public class BenchmarkTest01174 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01175.java b/OWASP DATASET/BenchmarkTest01175.java new file mode 100644 index 0000000000000000000000000000000000000000..0a86c428516219401ec091d2c110a8c257f4107d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01175.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01175") +public class BenchmarkTest01175 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01176.java b/OWASP DATASET/BenchmarkTest01176.java new file mode 100644 index 0000000000000000000000000000000000000000..78ec83258b48f1ac237bbbd55949c2e2387db453 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01176.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01176") +public class BenchmarkTest01176 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01177.java b/OWASP DATASET/BenchmarkTest01177.java new file mode 100644 index 0000000000000000000000000000000000000000..015ae9f4a86d12639fb722afd252fdc991179b1c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01177.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01177") +public class BenchmarkTest01177 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01178.java b/OWASP DATASET/BenchmarkTest01178.java new file mode 100644 index 0000000000000000000000000000000000000000..81e39130636391f65f8144779539a181fafc2a85 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01178.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01178") +public class BenchmarkTest01178 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar.toCharArray()); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz69428 = new StringBuilder(param); + String bar = sbxyz69428.append("_SafeStuff").toString(); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01179.java b/OWASP DATASET/BenchmarkTest01179.java new file mode 100644 index 0000000000000000000000000000000000000000..3ab24e899ef725a11d1f4570bd58ee08f411bae9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01179.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01179") +public class BenchmarkTest01179 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01180.java b/OWASP DATASET/BenchmarkTest01180.java new file mode 100644 index 0000000000000000000000000000000000000000..ea0bbd158ea41736ae5dcc1f2220dd542dc4d64a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01180.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01180") +public class BenchmarkTest01180 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01181.java b/OWASP DATASET/BenchmarkTest01181.java new file mode 100644 index 0000000000000000000000000000000000000000..bfe1a561c997e208a4eaa7a643ef2acf9a006e78 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01181.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01181") +public class BenchmarkTest01181 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar.toCharArray()); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01182.java b/OWASP DATASET/BenchmarkTest01182.java new file mode 100644 index 0000000000000000000000000000000000000000..ff6b5c3a2a3f6f097aecda1b622bb6b9d8aecfca --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01182.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01182") +public class BenchmarkTest01182 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01182"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01183.java b/OWASP DATASET/BenchmarkTest01183.java new file mode 100644 index 0000000000000000000000000000000000000000..b2e2363a8aa2bea3033e7da5f811ef4185704889 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01183.java @@ -0,0 +1,134 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01183") +public class BenchmarkTest01183 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01183"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + float rand = new java.util.Random().nextFloat(); + String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "Floyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01184.java b/OWASP DATASET/BenchmarkTest01184.java new file mode 100644 index 0000000000000000000000000000000000000000..d190368fae302ff8df07d9d9786f65e4270a96e1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01184.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01184") +public class BenchmarkTest01184 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01184"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + double stuff = new java.util.Random().nextGaussian(); + String rememberMeKey = Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "Gayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter() + .println("Weak Randomness Test java.util.Random.nextGaussian() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01185.java b/OWASP DATASET/BenchmarkTest01185.java new file mode 100644 index 0000000000000000000000000000000000000000..e72afce89427a659bd433938e56b20b9c1df2ff8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01185.java @@ -0,0 +1,105 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest01185") +public class BenchmarkTest01185 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01185"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01186.java b/OWASP DATASET/BenchmarkTest01186.java new file mode 100644 index 0000000000000000000000000000000000000000..387dd3148413d7031d06a382984efa4b881cd927 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01186.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest01186") +public class BenchmarkTest01186 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01186"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01187.java b/OWASP DATASET/BenchmarkTest01187.java new file mode 100644 index 0000000000000000000000000000000000000000..801a5df382afedf50ed4294171c6938461e38dac --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01187.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest01187") +public class BenchmarkTest01187 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01187"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01188.java b/OWASP DATASET/BenchmarkTest01188.java new file mode 100644 index 0000000000000000000000000000000000000000..bb5ae988893e104246d3ccd09be51b4456a5b23a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01188.java @@ -0,0 +1,69 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01188") +public class BenchmarkTest01188 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write("Parameter value: " + bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01189.java b/OWASP DATASET/BenchmarkTest01189.java new file mode 100644 index 0000000000000000000000000000000000000000..e0f9841e5ad59c75e9692b3dd2806ba672b20085 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01189.java @@ -0,0 +1,101 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01189") +public class BenchmarkTest01189 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01189"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ping -c1 "); + args = new String[] {a1, a2, cmd + bar}; + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01190.java b/OWASP DATASET/BenchmarkTest01190.java new file mode 100644 index 0000000000000000000000000000000000000000..f222fea52697b69eac9dbf417999c8bc6f850dc1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01190.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01190") +public class BenchmarkTest01190 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01190"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01191.java b/OWASP DATASET/BenchmarkTest01191.java new file mode 100644 index 0000000000000000000000000000000000000000..99901bd4908eb71545de53fdb7a91f41b6ef5ab2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01191.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01191") +public class BenchmarkTest01191 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01191"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01192.java b/OWASP DATASET/BenchmarkTest01192.java new file mode 100644 index 0000000000000000000000000000000000000000..0ac03a63dab75b53f3ae1b783f92f9159cd71090 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01192.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01192") +public class BenchmarkTest01192 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01192"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01193.java b/OWASP DATASET/BenchmarkTest01193.java new file mode 100644 index 0000000000000000000000000000000000000000..48ec2e5ead7dfc320ecb41f40da88842421fe994 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01193.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01193") +public class BenchmarkTest01193 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01193"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01194.java b/OWASP DATASET/BenchmarkTest01194.java new file mode 100644 index 0000000000000000000000000000000000000000..af7933405bf8c495de0cf5aeeadce61fab15d2d2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01194.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01194") +public class BenchmarkTest01194 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01194"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01195.java b/OWASP DATASET/BenchmarkTest01195.java new file mode 100644 index 0000000000000000000000000000000000000000..11a6d128aec27da744149056a180f4821ebb37c1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01195.java @@ -0,0 +1,128 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01195") +public class BenchmarkTest01195 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01195"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01196.java b/OWASP DATASET/BenchmarkTest01196.java new file mode 100644 index 0000000000000000000000000000000000000000..fae24539471af98926521752b24675f670253a68 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01196.java @@ -0,0 +1,128 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01196") +public class BenchmarkTest01196 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01196"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + double rand = getNextNumber(numGen); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonatella"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + double getNextNumber(java.util.Random generator) { + return generator.nextDouble(); + } + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01197.java b/OWASP DATASET/BenchmarkTest01197.java new file mode 100644 index 0000000000000000000000000000000000000000..ac1e5a8d248a916745c6905af7842cae494c7ef7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01197.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01197") +public class BenchmarkTest01197 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01197"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz6066 = new StringBuilder(param); + String bar = sbxyz6066.append("_SafeStuff").toString(); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01198.java b/OWASP DATASET/BenchmarkTest01198.java new file mode 100644 index 0000000000000000000000000000000000000000..252663997787ccec563ff3c5e8fc8dfe9855e1d6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01198.java @@ -0,0 +1,123 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01198") +public class BenchmarkTest01198 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01198"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01199.java b/OWASP DATASET/BenchmarkTest01199.java new file mode 100644 index 0000000000000000000000000000000000000000..d10984947cf6ed96998d8ab928293bb13a03a907 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01199.java @@ -0,0 +1,122 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01199") +public class BenchmarkTest01199 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01199"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + float rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextFloat(); + String rememberMeKey = + Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeFloyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextFloat() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextFloat() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01200.java b/OWASP DATASET/BenchmarkTest01200.java new file mode 100644 index 0000000000000000000000000000000000000000..34974a7e54dfe3ea03784526a0c548cfa8b7b980 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01200.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01200") +public class BenchmarkTest01200 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01200"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + float rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextFloat(); + String rememberMeKey = + Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeFloyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextFloat() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextFloat() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01201.java b/OWASP DATASET/BenchmarkTest01201.java new file mode 100644 index 0000000000000000000000000000000000000000..591136e77e88275bf366e31e2bab848cdce149f4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01201.java @@ -0,0 +1,126 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01201") +public class BenchmarkTest01201 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01201"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + double stuff = java.security.SecureRandom.getInstance("SHA1PRNG").nextGaussian(); + String rememberMeKey = + Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "SafeGayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextGaussian() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextGaussian() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01202.java b/OWASP DATASET/BenchmarkTest01202.java new file mode 100644 index 0000000000000000000000000000000000000000..1e76029a311e4046224dad35e33f23ef339bf4d6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01202.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01202") +public class BenchmarkTest01202 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01202"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + double stuff = java.security.SecureRandom.getInstance("SHA1PRNG").nextGaussian(); + String rememberMeKey = + Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "SafeGayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextGaussian() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextGaussian() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01203.java b/OWASP DATASET/BenchmarkTest01203.java new file mode 100644 index 0000000000000000000000000000000000000000..0ea42f82de80e601a44a276a5b5b5e2f440c7bac --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01203.java @@ -0,0 +1,80 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01203") +public class BenchmarkTest01203 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01203"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map72700 = new java.util.HashMap(); + map72700.put("keyA-72700", "a-Value"); // put some stuff in the collection + map72700.put("keyB-72700", param); // put it in a collection + map72700.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map72700.get("keyB-72700"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01204.java b/OWASP DATASET/BenchmarkTest01204.java new file mode 100644 index 0000000000000000000000000000000000000000..f386d258d33be5a2e03d038946f6f61c16366b7c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01204.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01204") +public class BenchmarkTest01204 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01204"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a40584 = param; // assign + StringBuilder b40584 = new StringBuilder(a40584); // stick in stringbuilder + b40584.append(" SafeStuff"); // append some safe content + b40584.replace( + b40584.length() - "Chars".length(), + b40584.length(), + "Chars"); // replace some of the end content + java.util.HashMap map40584 = new java.util.HashMap(); + map40584.put("key40584", b40584.toString()); // put in a collection + String c40584 = (String) map40584.get("key40584"); // get it back out + String d40584 = c40584.substring(0, c40584.length() - 1); // extract most of it + String e40584 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d40584.getBytes()))); // B64 encode and decode it + String f40584 = e40584.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f40584); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01205.java b/OWASP DATASET/BenchmarkTest01205.java new file mode 100644 index 0000000000000000000000000000000000000000..712a484aadf4780c814d7b56d800f52418d94014 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01205.java @@ -0,0 +1,80 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01205") +public class BenchmarkTest01205 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01205"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01206.java b/OWASP DATASET/BenchmarkTest01206.java new file mode 100644 index 0000000000000000000000000000000000000000..f6ea3b71f00b49c5fc84588b7a8fea60091fe1e8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01206.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01206") +public class BenchmarkTest01206 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01206"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz14623 = new StringBuilder(param); + bar = + sbxyz14623 + .replace(param.length() - "Z".length(), param.length(), "Z") + .toString(); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01207.java b/OWASP DATASET/BenchmarkTest01207.java new file mode 100644 index 0000000000000000000000000000000000000000..cd136f6d13977eb3a76e2f7a204176769ebb966e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01207.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01207") +public class BenchmarkTest01207 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01207"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String^,java.lang.Object) + request.getSession().setAttribute(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: '10340' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map95902 = new java.util.HashMap(); + map95902.put("keyA-95902", "a_Value"); // put some stuff in the collection + map95902.put("keyB-95902", param); // put it in a collection + map95902.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map95902.get("keyB-95902"); // get it back out + bar = (String) map95902.get("keyA-95902"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01208.java b/OWASP DATASET/BenchmarkTest01208.java new file mode 100644 index 0000000000000000000000000000000000000000..ec6c59f2643fe98e3862bf14a092732844b1a6c2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01208.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01208") +public class BenchmarkTest01208 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01208"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01209.java b/OWASP DATASET/BenchmarkTest01209.java new file mode 100644 index 0000000000000000000000000000000000000000..ec84cdcafe65b66ddfaef896ff724cbe12d149f9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01209.java @@ -0,0 +1,93 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01209") +public class BenchmarkTest01209 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01209"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01210.java b/OWASP DATASET/BenchmarkTest01210.java new file mode 100644 index 0000000000000000000000000000000000000000..37470a27d40e282e1727351ca3ef4c03730c339d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01210.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01210") +public class BenchmarkTest01210 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01210"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map86576 = new java.util.HashMap(); + map86576.put("keyA-86576", "a-Value"); // put some stuff in the collection + map86576.put("keyB-86576", param); // put it in a collection + map86576.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map86576.get("keyB-86576"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01211.java b/OWASP DATASET/BenchmarkTest01211.java new file mode 100644 index 0000000000000000000000000000000000000000..a20772cf94273b6d18a0bbba74cd152556b515a3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01211.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01211") +public class BenchmarkTest01211 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01211"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01212.java b/OWASP DATASET/BenchmarkTest01212.java new file mode 100644 index 0000000000000000000000000000000000000000..00f97fa3b01100f9c020b1833c22a5c9d29524b7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01212.java @@ -0,0 +1,93 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01212") +public class BenchmarkTest01212 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01212"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, new int[] {1, 2}); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01213.java b/OWASP DATASET/BenchmarkTest01213.java new file mode 100644 index 0000000000000000000000000000000000000000..408861e5e6fea6b74f0ee4f457bf1b51c98a2497 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01213.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01213") +public class BenchmarkTest01213 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01213"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, new String[] {"Column1", "Column2"}); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01214.java b/OWASP DATASET/BenchmarkTest01214.java new file mode 100644 index 0000000000000000000000000000000000000000..8750d62af5280336be34f41f7beddd3990579380 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01214.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01214") +public class BenchmarkTest01214 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01214"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + // System.out.println("no results for query: " + sql + " because the Spring batchUpdate + // method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01215.java b/OWASP DATASET/BenchmarkTest01215.java new file mode 100644 index 0000000000000000000000000000000000000000..2e39a83935b641b7041fe5343c2d5a7e2c87ef86 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01215.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01215") +public class BenchmarkTest01215 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01215"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // Long results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForLong(sql); + Long results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Long.class); + response.getWriter().println("Your results are: " + String.valueOf(results)); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01216.java b/OWASP DATASET/BenchmarkTest01216.java new file mode 100644 index 0000000000000000000000000000000000000000..f9bbfe9d9d99a8792fa90aaf77218009817ed8e3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01216.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01216") +public class BenchmarkTest01216 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01216"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.addBatch(sql); + int[] counts = statement.executeBatch(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(sql, counts, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01217.java b/OWASP DATASET/BenchmarkTest01217.java new file mode 100644 index 0000000000000000000000000000000000000000..0e73e684f88a445883baa123875e13d8291346bb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01217.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01217") +public class BenchmarkTest01217 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01217"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.addBatch(sql); + int[] counts = statement.executeBatch(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(sql, counts, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a89502 = param; // assign + StringBuilder b89502 = new StringBuilder(a89502); // stick in stringbuilder + b89502.append(" SafeStuff"); // append some safe content + b89502.replace( + b89502.length() - "Chars".length(), + b89502.length(), + "Chars"); // replace some of the end content + java.util.HashMap map89502 = new java.util.HashMap(); + map89502.put("key89502", b89502.toString()); // put in a collection + String c89502 = (String) map89502.get("key89502"); // get it back out + String d89502 = c89502.substring(0, c89502.length() - 1); // extract most of it + String e89502 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d89502.getBytes()))); // B64 encode and decode it + String f89502 = e89502.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g89502 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g89502); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01218.java b/OWASP DATASET/BenchmarkTest01218.java new file mode 100644 index 0000000000000000000000000000000000000000..81c5ad2ba3a91324c9b1ab834d2530939a43a8bc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01218.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01218") +public class BenchmarkTest01218 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01218"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.addBatch(sql); + int[] counts = statement.executeBatch(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(sql, counts, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01219.java b/OWASP DATASET/BenchmarkTest01219.java new file mode 100644 index 0000000000000000000000000000000000000000..18ba13eb338cf66320984a8b93bfaf56d6cc10d8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01219.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01219") +public class BenchmarkTest01219 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01219"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + java.sql.ResultSet rs = statement.executeQuery(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map23263 = new java.util.HashMap(); + map23263.put("keyA-23263", "a_Value"); // put some stuff in the collection + map23263.put("keyB-23263", param); // put it in a collection + map23263.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map23263.get("keyB-23263"); // get it back out + bar = (String) map23263.get("keyA-23263"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01220.java b/OWASP DATASET/BenchmarkTest01220.java new file mode 100644 index 0000000000000000000000000000000000000000..adad23ef0c0335cd6b5b921ad3eeb4f413a6fc34 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01220.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01220") +public class BenchmarkTest01220 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01220"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01221.java b/OWASP DATASET/BenchmarkTest01221.java new file mode 100644 index 0000000000000000000000000000000000000000..ab465982f457b48b8670ccc3001f9e0e96778a8e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01221.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01221") +public class BenchmarkTest01221 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01221"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01222.java b/OWASP DATASET/BenchmarkTest01222.java new file mode 100644 index 0000000000000000000000000000000000000000..6455a87a00822f56ade568b9338441b115578be3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01222.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01222") +public class BenchmarkTest01222 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01222"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map25738 = new java.util.HashMap(); + map25738.put("keyA-25738", "a-Value"); // put some stuff in the collection + map25738.put("keyB-25738", param); // put it in a collection + map25738.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map25738.get("keyB-25738"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01223.java b/OWASP DATASET/BenchmarkTest01223.java new file mode 100644 index 0000000000000000000000000000000000000000..91bca7d374b0941468ddee36f217c5a50a4da267 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01223.java @@ -0,0 +1,122 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest01223") +public class BenchmarkTest01223 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01223"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + org.w3c.dom.NodeList nodeList = + (org.w3c.dom.NodeList) + xp.compile(expression) + .evaluate(xmlDocument, javax.xml.xpath.XPathConstants.NODESET); + + response.getWriter().println("Your query results are:
"); + + for (int i = 0; i < nodeList.getLength(); i++) { + org.w3c.dom.Element value = (org.w3c.dom.Element) nodeList.item(i); + response.getWriter().println(value.getTextContent() + "
"); + } + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01224.java b/OWASP DATASET/BenchmarkTest01224.java new file mode 100644 index 0000000000000000000000000000000000000000..d03191227d57c8edc755352ba4f04b29db17a0c2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01224.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest01224") +public class BenchmarkTest01224 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01224"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + String result = xp.evaluate(expression, xmlDocument); + + response.getWriter().println("Your query results are: " + result + "
"); + + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01225.java b/OWASP DATASET/BenchmarkTest01225.java new file mode 100644 index 0000000000000000000000000000000000000000..a44cbbe5e29783439c02d8579951e508d68d9370 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01225.java @@ -0,0 +1,101 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest01225") +public class BenchmarkTest01225 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest01225"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + String result = xp.evaluate(expression, xmlDocument); + + response.getWriter().println("Your query results are: " + result + "
"); + + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01226.java b/OWASP DATASET/BenchmarkTest01226.java new file mode 100644 index 0000000000000000000000000000000000000000..e0948f5030872782f958eed369675e84e889c199 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01226.java @@ -0,0 +1,161 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01226") +public class BenchmarkTest01226 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01226"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01227.java b/OWASP DATASET/BenchmarkTest01227.java new file mode 100644 index 0000000000000000000000000000000000000000..9dd8530ed2a235a6ac8c2251c05c32173db4a8b9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01227.java @@ -0,0 +1,167 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01227") +public class BenchmarkTest01227 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01227"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz39213 = new StringBuilder(param); + bar = + sbxyz39213 + .replace(param.length() - "Z".length(), param.length(), "Z") + .toString(); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01228.java b/OWASP DATASET/BenchmarkTest01228.java new file mode 100644 index 0000000000000000000000000000000000000000..b5c4eb89cf11b059b7bd993d9e3ce803c88b1f6e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01228.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01228") +public class BenchmarkTest01228 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01228"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01229.java b/OWASP DATASET/BenchmarkTest01229.java new file mode 100644 index 0000000000000000000000000000000000000000..b786ad062f189aeef6c8c70b6ec05233f0ca415b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01229.java @@ -0,0 +1,132 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01229") +public class BenchmarkTest01229 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01229"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01230.java b/OWASP DATASET/BenchmarkTest01230.java new file mode 100644 index 0000000000000000000000000000000000000000..aa88ecca16eda21e0fcede2a080402a563080aae --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01230.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01230") +public class BenchmarkTest01230 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01230"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz45958 = new StringBuilder(param); + String bar = sbxyz45958.append("_SafeStuff").toString(); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01231.java b/OWASP DATASET/BenchmarkTest01231.java new file mode 100644 index 0000000000000000000000000000000000000000..2a1893a8f4e4dc4efe86561b2aeaeae0c6b03f83 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01231.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01231") +public class BenchmarkTest01231 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01231"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map35717 = new java.util.HashMap(); + map35717.put("keyA-35717", "a-Value"); // put some stuff in the collection + map35717.put("keyB-35717", param); // put it in a collection + map35717.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map35717.get("keyB-35717"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01232.java b/OWASP DATASET/BenchmarkTest01232.java new file mode 100644 index 0000000000000000000000000000000000000000..f78d3128fda53ff40ff09cf38d71d95fcce61a81 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01232.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01232") +public class BenchmarkTest01232 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01232"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01233.java b/OWASP DATASET/BenchmarkTest01233.java new file mode 100644 index 0000000000000000000000000000000000000000..3f7c67eaebc68c8010bd9463efa1bda84a0c3efc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01233.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01233") +public class BenchmarkTest01233 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01233"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01234.java b/OWASP DATASET/BenchmarkTest01234.java new file mode 100644 index 0000000000000000000000000000000000000000..ee77bafec09c36372c72393522e3e7ea81018938 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01234.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01234") +public class BenchmarkTest01234 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01234"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + java.io.File fileTarget = + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR, bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01235.java b/OWASP DATASET/BenchmarkTest01235.java new file mode 100644 index 0000000000000000000000000000000000000000..68d4d76bc4c2afc19b9f675cd928611bbf5296d7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01235.java @@ -0,0 +1,100 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01235") +public class BenchmarkTest01235 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01235"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + // FILE URIs are tricky because they are different between Mac and Windows because of lack + // of standardization. + // Mac requires an extra slash for some reason. + String startURIslashes = ""; + if (System.getProperty("os.name").indexOf("Windows") != -1) + if (System.getProperty("os.name").indexOf("Windows") != -1) startURIslashes = "/"; + else startURIslashes = "//"; + + try { + java.net.URI fileURI = + new java.net.URI( + "file:" + + startURIslashes + + org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + .replace('\\', '/') + .replace(' ', '_') + + bar); + java.io.File fileTarget = new java.io.File(fileURI); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } catch (java.net.URISyntaxException e) { + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map13886 = new java.util.HashMap(); + map13886.put("keyA-13886", "a-Value"); // put some stuff in the collection + map13886.put("keyB-13886", param); // put it in a collection + map13886.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map13886.get("keyB-13886"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01236.java b/OWASP DATASET/BenchmarkTest01236.java new file mode 100644 index 0000000000000000000000000000000000000000..d120bf48fe57ec4dc21fca976eeb0f5bdaed0b25 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01236.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01236") +public class BenchmarkTest01236 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01236"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + // FILE URIs are tricky because they are different between Mac and Windows because of lack + // of standardization. + // Mac requires an extra slash for some reason. + String startURIslashes = ""; + if (System.getProperty("os.name").indexOf("Windows") != -1) + if (System.getProperty("os.name").indexOf("Windows") != -1) startURIslashes = "/"; + else startURIslashes = "//"; + + try { + java.net.URI fileURI = + new java.net.URI( + "file:" + + startURIslashes + + org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + .replace('\\', '/') + .replace(' ', '_') + + bar); + java.io.File fileTarget = new java.io.File(fileURI); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } catch (java.net.URISyntaxException e) { + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01237.java b/OWASP DATASET/BenchmarkTest01237.java new file mode 100644 index 0000000000000000000000000000000000000000..93447eb21d876c6e5bbcd198ae79d83e119c8685 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01237.java @@ -0,0 +1,100 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01237") +public class BenchmarkTest01237 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01237"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + // FILE URIs are tricky because they are different between Mac and Windows because of lack + // of standardization. + // Mac requires an extra slash for some reason. + String startURIslashes = ""; + if (System.getProperty("os.name").indexOf("Windows") != -1) + if (System.getProperty("os.name").indexOf("Windows") != -1) startURIslashes = "/"; + else startURIslashes = "//"; + + try { + java.net.URI fileURI = + new java.net.URI( + "file:" + + startURIslashes + + org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + .replace('\\', '/') + .replace(' ', '_') + + bar); + java.io.File fileTarget = new java.io.File(fileURI); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } catch (java.net.URISyntaxException e) { + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01238.java b/OWASP DATASET/BenchmarkTest01238.java new file mode 100644 index 0000000000000000000000000000000000000000..be77a285efb5dddc5077346cc3fc07e421e87353 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01238.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01238") +public class BenchmarkTest01238 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01238"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName), false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01239.java b/OWASP DATASET/BenchmarkTest01239.java new file mode 100644 index 0000000000000000000000000000000000000000..4c92a0c4bb86bd48ed0a85cd4ea16381777ad9a8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01239.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01239") +public class BenchmarkTest01239 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01239"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + try ( + // Create the file first so the test won't throw an exception if it doesn't exist. + // Note: Don't actually do this because this method signature could cause a tool to find + // THIS file constructor + // as a vuln, rather than the File signature we are trying to actually test. + // If necessary, just run the benchmark twice. The 1st run should create all the necessary + // files. + // new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar).createNewFile(); + + java.io.FileOutputStream fos = + new java.io.FileOutputStream(new java.io.FileInputStream(fileName).getFD()); ) { + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01240.java b/OWASP DATASET/BenchmarkTest01240.java new file mode 100644 index 0000000000000000000000000000000000000000..ed44fadc1bfd6070c194bf6cb70fa19b6753da41 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01240.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01240") +public class BenchmarkTest01240 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01240"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01241.java b/OWASP DATASET/BenchmarkTest01241.java new file mode 100644 index 0000000000000000000000000000000000000000..2ff939b3344a881c91787c75ef7b867c744bdd85 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01241.java @@ -0,0 +1,118 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest01241") +public class BenchmarkTest01241 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01241"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + bar + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + + javax.naming.directory.DirContext ctx = ads.getDirContext(); + javax.naming.directory.InitialDirContext idc = + (javax.naming.directory.InitialDirContext) ctx; + boolean found = false; + javax.naming.NamingEnumeration results = + idc.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01242.java b/OWASP DATASET/BenchmarkTest01242.java new file mode 100644 index 0000000000000000000000000000000000000000..9ff6d4ec9ef2c788a10b83c649afa334f4fa510b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01242.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest01242") +public class BenchmarkTest01242 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01242"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + bar + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + + javax.naming.directory.DirContext ctx = ads.getDirContext(); + javax.naming.directory.InitialDirContext idc = + (javax.naming.directory.InitialDirContext) ctx; + boolean found = false; + javax.naming.NamingEnumeration results = + idc.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01243.java b/OWASP DATASET/BenchmarkTest01243.java new file mode 100644 index 0000000000000000000000000000000000000000..0ba48af860c8d9051fd0eaee4a2a3d316c03604c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01243.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest01243") +public class BenchmarkTest01243 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01243"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person)(uid=" + bar + "))"; + + javax.naming.directory.DirContext ctx = ads.getDirContext(); + javax.naming.directory.InitialDirContext idc = + (javax.naming.directory.InitialDirContext) ctx; + boolean found = false; + javax.naming.NamingEnumeration results = + idc.search(base, filter, sc); + + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01244.java b/OWASP DATASET/BenchmarkTest01244.java new file mode 100644 index 0000000000000000000000000000000000000000..19ce0543dd318aef65783b48912934c910023687 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01244.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01244") +public class BenchmarkTest01244 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01244"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("SHA1", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01245.java b/OWASP DATASET/BenchmarkTest01245.java new file mode 100644 index 0000000000000000000000000000000000000000..f032687ea826340eb97794f832afd68dddd0403e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01245.java @@ -0,0 +1,126 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01245") +public class BenchmarkTest01245 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01245"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("sha-384", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("sha-384", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01246.java b/OWASP DATASET/BenchmarkTest01246.java new file mode 100644 index 0000000000000000000000000000000000000000..f5d13eda2d94daa04ca27b9f7e5bd803592661cf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01246.java @@ -0,0 +1,132 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01246") +public class BenchmarkTest01246 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01246"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01247.java b/OWASP DATASET/BenchmarkTest01247.java new file mode 100644 index 0000000000000000000000000000000000000000..d319bd87543c0a6def896cfc3dc3c190918564cf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01247.java @@ -0,0 +1,111 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01247") +public class BenchmarkTest01247 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01247"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01248.java b/OWASP DATASET/BenchmarkTest01248.java new file mode 100644 index 0000000000000000000000000000000000000000..eb713a85ab4a61a125bdc8ae4e44c6d9534f2490 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01248.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01248") +public class BenchmarkTest01248 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01248"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01249.java b/OWASP DATASET/BenchmarkTest01249.java new file mode 100644 index 0000000000000000000000000000000000000000..bd3f2cb2b70ce3cdc086d88ce333c3156fa02822 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01249.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01249") +public class BenchmarkTest01249 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01249"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01250.java b/OWASP DATASET/BenchmarkTest01250.java new file mode 100644 index 0000000000000000000000000000000000000000..1034a240c03095a7a9b19ec59e15507b3fa223af --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01250.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01250") +public class BenchmarkTest01250 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01250"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01251.java b/OWASP DATASET/BenchmarkTest01251.java new file mode 100644 index 0000000000000000000000000000000000000000..d5646d3a191f3fba8ed6ca7972a459a30a4dfa02 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01251.java @@ -0,0 +1,66 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01251") +public class BenchmarkTest01251 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01251"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + java.io.PrintWriter out = response.getWriter(); + out.write("\n\n\n

"); + out.format(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + out.write("\n

\n\n"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01252.java b/OWASP DATASET/BenchmarkTest01252.java new file mode 100644 index 0000000000000000000000000000000000000000..8516f1f1d12a881f4c5ed910f56a53f267cfeab8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01252.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01252") +public class BenchmarkTest01252 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01252"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(java.util.Locale.US, bar, obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01253.java b/OWASP DATASET/BenchmarkTest01253.java new file mode 100644 index 0000000000000000000000000000000000000000..2535f4e42f8c1b64752e3cf4cad9a7863c1019df --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01253.java @@ -0,0 +1,68 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01253") +public class BenchmarkTest01253 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01253"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(bar, obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map15481 = new java.util.HashMap(); + map15481.put("keyA-15481", "a-Value"); // put some stuff in the collection + map15481.put("keyB-15481", param); // put it in a collection + map15481.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map15481.get("keyB-15481"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01254.java b/OWASP DATASET/BenchmarkTest01254.java new file mode 100644 index 0000000000000000000000000000000000000000..53d3591ea9b6f268a67220475901e94cc21f4255 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01254.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01254") +public class BenchmarkTest01254 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01254"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar.toCharArray()); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a23874 = param; // assign + StringBuilder b23874 = new StringBuilder(a23874); // stick in stringbuilder + b23874.append(" SafeStuff"); // append some safe content + b23874.replace( + b23874.length() - "Chars".length(), + b23874.length(), + "Chars"); // replace some of the end content + java.util.HashMap map23874 = new java.util.HashMap(); + map23874.put("key23874", b23874.toString()); // put in a collection + String c23874 = (String) map23874.get("key23874"); // get it back out + String d23874 = c23874.substring(0, c23874.length() - 1); // extract most of it + String e23874 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d23874.getBytes()))); // B64 encode and decode it + String f23874 = e23874.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f23874); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01255.java b/OWASP DATASET/BenchmarkTest01255.java new file mode 100644 index 0000000000000000000000000000000000000000..cb27a121dfd56c99a960e17433892237b6089923 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01255.java @@ -0,0 +1,62 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01255") +public class BenchmarkTest01255 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01255"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar.toCharArray()); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01256.java b/OWASP DATASET/BenchmarkTest01256.java new file mode 100644 index 0000000000000000000000000000000000000000..c87b7124676c9d0d4eb738c0a83b8a1e539e7a9d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01256.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01256") +public class BenchmarkTest01256 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01256"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar.toCharArray()); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01257.java b/OWASP DATASET/BenchmarkTest01257.java new file mode 100644 index 0000000000000000000000000000000000000000..2a4f80410a2fbf84159b5fac2e7082822afbcacf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01257.java @@ -0,0 +1,64 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01257") +public class BenchmarkTest01257 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01257"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01258.java b/OWASP DATASET/BenchmarkTest01258.java new file mode 100644 index 0000000000000000000000000000000000000000..9aaac3b2199cafb1167af8b41dd7ac46fe874c64 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01258.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01258") +public class BenchmarkTest01258 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01258"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01259.java b/OWASP DATASET/BenchmarkTest01259.java new file mode 100644 index 0000000000000000000000000000000000000000..4b3b34282d3d56582c9ce540a0fbf59f0f534adf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01259.java @@ -0,0 +1,68 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01259") +public class BenchmarkTest01259 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01259"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {bar, "b"}; + response.getWriter().printf("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map26093 = new java.util.HashMap(); + map26093.put("keyA-26093", "a-Value"); // put some stuff in the collection + map26093.put("keyB-26093", param); // put it in a collection + map26093.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map26093.get("keyB-26093"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01260.java b/OWASP DATASET/BenchmarkTest01260.java new file mode 100644 index 0000000000000000000000000000000000000000..6c4e54339028351f3df3f2d241f8bb94c5733dd4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01260.java @@ -0,0 +1,64 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01260") +public class BenchmarkTest01260 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01260"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {bar, "b"}; + response.getWriter().printf("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01261.java b/OWASP DATASET/BenchmarkTest01261.java new file mode 100644 index 0000000000000000000000000000000000000000..935e3dc8bb34fdb3baf5fa2202b48f1b02a4e426 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01261.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01261") +public class BenchmarkTest01261 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01261"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar.toCharArray()); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a34194 = param; // assign + StringBuilder b34194 = new StringBuilder(a34194); // stick in stringbuilder + b34194.append(" SafeStuff"); // append some safe content + b34194.replace( + b34194.length() - "Chars".length(), + b34194.length(), + "Chars"); // replace some of the end content + java.util.HashMap map34194 = new java.util.HashMap(); + map34194.put("key34194", b34194.toString()); // put in a collection + String c34194 = (String) map34194.get("key34194"); // get it back out + String d34194 = c34194.substring(0, c34194.length() - 1); // extract most of it + String e34194 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d34194.getBytes()))); // B64 encode and decode it + String f34194 = e34194.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f34194); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01262.java b/OWASP DATASET/BenchmarkTest01262.java new file mode 100644 index 0000000000000000000000000000000000000000..deea4c37206abae3968209014e7c1fef4bc2e668 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01262.java @@ -0,0 +1,65 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01262") +public class BenchmarkTest01262 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01262"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar.toCharArray()); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01263.java b/OWASP DATASET/BenchmarkTest01263.java new file mode 100644 index 0000000000000000000000000000000000000000..dfc717c05ef100227a3cf0eb40d7c48542ce5ab6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01263.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01263") +public class BenchmarkTest01263 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01263"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar.toCharArray()); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01264.java b/OWASP DATASET/BenchmarkTest01264.java new file mode 100644 index 0000000000000000000000000000000000000000..5118d4eb3542d6396dafdcf856d2fdae60f5e430 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01264.java @@ -0,0 +1,62 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01264") +public class BenchmarkTest01264 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01264"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01265.java b/OWASP DATASET/BenchmarkTest01265.java new file mode 100644 index 0000000000000000000000000000000000000000..68c07666f250dd4a6d4eb730e154d825577423bc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01265.java @@ -0,0 +1,71 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01265") +public class BenchmarkTest01265 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01265"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar.toCharArray(), 0, length); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01266.java b/OWASP DATASET/BenchmarkTest01266.java new file mode 100644 index 0000000000000000000000000000000000000000..4b8d18249f46c412ff5e4ca565a469a4f66ad2b5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01266.java @@ -0,0 +1,67 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01266") +public class BenchmarkTest01266 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01266"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar.toCharArray(), 0, length); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01267.java b/OWASP DATASET/BenchmarkTest01267.java new file mode 100644 index 0000000000000000000000000000000000000000..947895c739ad8425d7ad42c399e562438626fcf0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01267.java @@ -0,0 +1,67 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01267") +public class BenchmarkTest01267 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01267"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map53210 = new java.util.HashMap(); + map53210.put("keyA-53210", "a-Value"); // put some stuff in the collection + map53210.put("keyB-53210", param); // put it in a collection + map53210.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map53210.get("keyB-53210"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01268.java b/OWASP DATASET/BenchmarkTest01268.java new file mode 100644 index 0000000000000000000000000000000000000000..77f7350fd0b209752cbeb12137bfd00f302b61a2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01268.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01268") +public class BenchmarkTest01268 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01268"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar, 0, length); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a92384 = param; // assign + StringBuilder b92384 = new StringBuilder(a92384); // stick in stringbuilder + b92384.append(" SafeStuff"); // append some safe content + b92384.replace( + b92384.length() - "Chars".length(), + b92384.length(), + "Chars"); // replace some of the end content + java.util.HashMap map92384 = new java.util.HashMap(); + map92384.put("key92384", b92384.toString()); // put in a collection + String c92384 = (String) map92384.get("key92384"); // get it back out + String d92384 = c92384.substring(0, c92384.length() - 1); // extract most of it + String e92384 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d92384.getBytes()))); // B64 encode and decode it + String f92384 = e92384.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f92384); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01269.java b/OWASP DATASET/BenchmarkTest01269.java new file mode 100644 index 0000000000000000000000000000000000000000..b5e4e746b001d79e22b19fdbdfb027cf8535bed9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01269.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01269") +public class BenchmarkTest01269 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01269"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String a1 = ""; + String a2 = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + } else { + a1 = "sh"; + a2 = "-c"; + } + String[] args = {a1, a2, "echo " + bar}; + + ProcessBuilder pb = new ProcessBuilder(); + + pb.command(args); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01270.java b/OWASP DATASET/BenchmarkTest01270.java new file mode 100644 index 0000000000000000000000000000000000000000..fb3f0246471abfdc6fd5e343e484194244b6d2fe --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01270.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01270") +public class BenchmarkTest01270 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01270"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String a1 = ""; + String a2 = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + } else { + a1 = "sh"; + a2 = "-c"; + } + String[] args = {a1, a2, "echo " + bar}; + + ProcessBuilder pb = new ProcessBuilder(args); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.lang.String[]) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01271.java b/OWASP DATASET/BenchmarkTest01271.java new file mode 100644 index 0000000000000000000000000000000000000000..11a10cac74840d1752a284c9e5f24ba060e2b1d1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01271.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01271") +public class BenchmarkTest01271 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01271"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + float rand = new java.util.Random().nextFloat(); + String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "Floyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a4086 = param; // assign + StringBuilder b4086 = new StringBuilder(a4086); // stick in stringbuilder + b4086.append(" SafeStuff"); // append some safe content + b4086.replace( + b4086.length() - "Chars".length(), + b4086.length(), + "Chars"); // replace some of the end content + java.util.HashMap map4086 = new java.util.HashMap(); + map4086.put("key4086", b4086.toString()); // put in a collection + String c4086 = (String) map4086.get("key4086"); // get it back out + String d4086 = c4086.substring(0, c4086.length() - 1); // extract most of it + String e4086 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d4086.getBytes()))); // B64 encode and decode it + String f4086 = e4086.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g4086 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g4086); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01272.java b/OWASP DATASET/BenchmarkTest01272.java new file mode 100644 index 0000000000000000000000000000000000000000..aa1f2043ee803197910d67de6de690f6c594bc09 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01272.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01272") +public class BenchmarkTest01272 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01272"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + double stuff = new java.util.Random().nextGaussian(); + String rememberMeKey = Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "Gayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter() + .println("Weak Randomness Test java.util.Random.nextGaussian() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01273.java b/OWASP DATASET/BenchmarkTest01273.java new file mode 100644 index 0000000000000000000000000000000000000000..9675abc8e35b48912f6757b4dd68f34be11dd23b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01273.java @@ -0,0 +1,111 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01273") +public class BenchmarkTest01273 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01273"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + double stuff = new java.util.Random().nextGaussian(); + String rememberMeKey = Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "Gayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter() + .println("Weak Randomness Test java.util.Random.nextGaussian() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01274.java b/OWASP DATASET/BenchmarkTest01274.java new file mode 100644 index 0000000000000000000000000000000000000000..2701368f79e641d32b5aaed722838bf2069f331c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01274.java @@ -0,0 +1,107 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01274") +public class BenchmarkTest01274 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01274"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + int randNumber = new java.util.Random().nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "Inga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt(int) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01275.java b/OWASP DATASET/BenchmarkTest01275.java new file mode 100644 index 0000000000000000000000000000000000000000..36d888a94ee2726b5632aa9c7acbdcd1492c5282 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01275.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01275") +public class BenchmarkTest01275 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01275"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + int randNumber = new java.util.Random().nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "Inga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt(int) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz27989 = new StringBuilder(param); + String bar = sbxyz27989.append("_SafeStuff").toString(); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01276.java b/OWASP DATASET/BenchmarkTest01276.java new file mode 100644 index 0000000000000000000000000000000000000000..a204e6bd69c296b574b10c818e6757895a2bc246 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01276.java @@ -0,0 +1,127 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01276") +public class BenchmarkTest01276 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01276"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a83599 = param; // assign + StringBuilder b83599 = new StringBuilder(a83599); // stick in stringbuilder + b83599.append(" SafeStuff"); // append some safe content + b83599.replace( + b83599.length() - "Chars".length(), + b83599.length(), + "Chars"); // replace some of the end content + java.util.HashMap map83599 = new java.util.HashMap(); + map83599.put("key83599", b83599.toString()); // put in a collection + String c83599 = (String) map83599.get("key83599"); // get it back out + String d83599 = c83599.substring(0, c83599.length() - 1); // extract most of it + String e83599 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d83599.getBytes()))); // B64 encode and decode it + String f83599 = e83599.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f83599); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01277.java b/OWASP DATASET/BenchmarkTest01277.java new file mode 100644 index 0000000000000000000000000000000000000000..93950e7f42a2e1456f8eacb35e95c7babe72199e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01277.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01277") +public class BenchmarkTest01277 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01277"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01278.java b/OWASP DATASET/BenchmarkTest01278.java new file mode 100644 index 0000000000000000000000000000000000000000..02bc3ea0a0a2017cffbb173ca1837dbfd6c96083 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01278.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01278") +public class BenchmarkTest01278 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01278"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01279.java b/OWASP DATASET/BenchmarkTest01279.java new file mode 100644 index 0000000000000000000000000000000000000000..48f709a2dd49f8b47ed1e8dc8aa671ead2a9f07e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01279.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01279") +public class BenchmarkTest01279 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01279"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01280.java b/OWASP DATASET/BenchmarkTest01280.java new file mode 100644 index 0000000000000000000000000000000000000000..4d52db5740ae6108c8a1d82401dd4a1063c88a24 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01280.java @@ -0,0 +1,93 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest01280") +public class BenchmarkTest01280 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01280"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01281.java b/OWASP DATASET/BenchmarkTest01281.java new file mode 100644 index 0000000000000000000000000000000000000000..d410447d980b838cb9d8d85fcdeed80f15682d48 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01281.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest01281") +public class BenchmarkTest01281 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01281"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01282.java b/OWASP DATASET/BenchmarkTest01282.java new file mode 100644 index 0000000000000000000000000000000000000000..54b5a00a2c546ac969a5652e4654e24dcfc9853c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01282.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest01282") +public class BenchmarkTest01282 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01282"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01283.java b/OWASP DATASET/BenchmarkTest01283.java new file mode 100644 index 0000000000000000000000000000000000000000..5e433deddf08d3eddd57dd20586439d0f131237b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01283.java @@ -0,0 +1,93 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest01283") +public class BenchmarkTest01283 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01283"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01284.java b/OWASP DATASET/BenchmarkTest01284.java new file mode 100644 index 0000000000000000000000000000000000000000..e75d8ff681807e1421f775e9f19a7cb1eb1419ea --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01284.java @@ -0,0 +1,72 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01284") +public class BenchmarkTest01284 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01284"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write("Parameter value: " + bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01285.java b/OWASP DATASET/BenchmarkTest01285.java new file mode 100644 index 0000000000000000000000000000000000000000..74bf8bfc72a4d929cfaf5466dc855c0797b2df51 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01285.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01285") +public class BenchmarkTest01285 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01285"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01286.java b/OWASP DATASET/BenchmarkTest01286.java new file mode 100644 index 0000000000000000000000000000000000000000..91d3dbad0c6bcc412dd7d804c1214f7d2647fc17 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01286.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01286") +public class BenchmarkTest01286 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01286"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ping -c1 "); + args = new String[] {a1, a2, cmd + bar}; + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01287.java b/OWASP DATASET/BenchmarkTest01287.java new file mode 100644 index 0000000000000000000000000000000000000000..4cb67e3cd9e561897e206f4e73607fa997889067 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01287.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01287") +public class BenchmarkTest01287 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01287"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01288.java b/OWASP DATASET/BenchmarkTest01288.java new file mode 100644 index 0000000000000000000000000000000000000000..5e131ae30a0a72aa44bf6e261f64bcffab38f770 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01288.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01288") +public class BenchmarkTest01288 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01288"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map58555 = new java.util.HashMap(); + map58555.put("keyA-58555", "a-Value"); // put some stuff in the collection + map58555.put("keyB-58555", param); // put it in a collection + map58555.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map58555.get("keyB-58555"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01289.java b/OWASP DATASET/BenchmarkTest01289.java new file mode 100644 index 0000000000000000000000000000000000000000..4b11dae8ba0974d52a895c896f1464d6008fb532 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01289.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01289") +public class BenchmarkTest01289 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01289"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01290.java b/OWASP DATASET/BenchmarkTest01290.java new file mode 100644 index 0000000000000000000000000000000000000000..ba1ee728989a36a331dd070b8c30d266985e5f36 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01290.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01290") +public class BenchmarkTest01290 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01290"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01291.java b/OWASP DATASET/BenchmarkTest01291.java new file mode 100644 index 0000000000000000000000000000000000000000..d7623494466ab81485e800c46acc51ee2972c5fb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01291.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01291") +public class BenchmarkTest01291 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01291"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz42950 = new StringBuilder(param); + bar = + sbxyz42950 + .replace(param.length() - "Z".length(), param.length(), "Z") + .toString(); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01292.java b/OWASP DATASET/BenchmarkTest01292.java new file mode 100644 index 0000000000000000000000000000000000000000..8cb40cd1fbb16b6bdec5958462251cfc21b6e8ad --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01292.java @@ -0,0 +1,135 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01292") +public class BenchmarkTest01292 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01292"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + getNextNumber(numGen, randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeBystander"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + void getNextNumber(java.util.Random generator, byte[] barray) { + generator.nextBytes(barray); + } + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01293.java b/OWASP DATASET/BenchmarkTest01293.java new file mode 100644 index 0000000000000000000000000000000000000000..b3e77419a45c0d64560cd3a3890eba58f67b28fa --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01293.java @@ -0,0 +1,132 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01293") +public class BenchmarkTest01293 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01293"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01294.java b/OWASP DATASET/BenchmarkTest01294.java new file mode 100644 index 0000000000000000000000000000000000000000..47cede1b9bbeb830d7bd7fa749a9eb8179472e20 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01294.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01294") +public class BenchmarkTest01294 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01294"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + float rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextFloat(); + String rememberMeKey = + Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeFloyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextFloat() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextFloat() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01295.java b/OWASP DATASET/BenchmarkTest01295.java new file mode 100644 index 0000000000000000000000000000000000000000..ddf8ebe411a8df74fda7692f638843b9e96be4e5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01295.java @@ -0,0 +1,135 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-02/BenchmarkTest01295") +public class BenchmarkTest01295 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01295"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + float rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextFloat(); + String rememberMeKey = + Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeFloyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextFloat() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextFloat() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a22205 = param; // assign + StringBuilder b22205 = new StringBuilder(a22205); // stick in stringbuilder + b22205.append(" SafeStuff"); // append some safe content + b22205.replace( + b22205.length() - "Chars".length(), + b22205.length(), + "Chars"); // replace some of the end content + java.util.HashMap map22205 = new java.util.HashMap(); + map22205.put("key22205", b22205.toString()); // put in a collection + String c22205 = (String) map22205.get("key22205"); // get it back out + String d22205 = c22205.substring(0, c22205.length() - 1); // extract most of it + String e22205 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d22205.getBytes()))); // B64 encode and decode it + String f22205 = e22205.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g22205 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g22205); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01296.java b/OWASP DATASET/BenchmarkTest01296.java new file mode 100644 index 0000000000000000000000000000000000000000..8ac9be45f75fc4f6dbc1188590b601472fa94a18 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01296.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01296") +public class BenchmarkTest01296 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01296"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + double stuff = java.security.SecureRandom.getInstance("SHA1PRNG").nextGaussian(); + String rememberMeKey = + Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "SafeGayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextGaussian() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextGaussian() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01297.java b/OWASP DATASET/BenchmarkTest01297.java new file mode 100644 index 0000000000000000000000000000000000000000..729e43e8ae0730e6ca43bcc5021015d04236515a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01297.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01297") +public class BenchmarkTest01297 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01297"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + int r = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "SafeIngrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01298.java b/OWASP DATASET/BenchmarkTest01298.java new file mode 100644 index 0000000000000000000000000000000000000000..9653641e492fcff0aef5ad50921596b0c914929f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01298.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01298") +public class BenchmarkTest01298 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01298"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + int r = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "SafeIngrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01299.java b/OWASP DATASET/BenchmarkTest01299.java new file mode 100644 index 0000000000000000000000000000000000000000..d2b2bb9955a8a618b2a7125da0d0ff776d2810ea --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01299.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01299") +public class BenchmarkTest01299 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01299"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01300.java b/OWASP DATASET/BenchmarkTest01300.java new file mode 100644 index 0000000000000000000000000000000000000000..03ad0b4aee23c6b76016ef1d7667010790b65b3d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01300.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01300") +public class BenchmarkTest01300 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01300"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01301.java b/OWASP DATASET/BenchmarkTest01301.java new file mode 100644 index 0000000000000000000000000000000000000000..42743c2a2db953f1c56468bc816b2bf4010d46fd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01301.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01301") +public class BenchmarkTest01301 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01301"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a11416 = param; // assign + StringBuilder b11416 = new StringBuilder(a11416); // stick in stringbuilder + b11416.append(" SafeStuff"); // append some safe content + b11416.replace( + b11416.length() - "Chars".length(), + b11416.length(), + "Chars"); // replace some of the end content + java.util.HashMap map11416 = new java.util.HashMap(); + map11416.put("key11416", b11416.toString()); // put in a collection + String c11416 = (String) map11416.get("key11416"); // get it back out + String d11416 = c11416.substring(0, c11416.length() - 1); // extract most of it + String e11416 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d11416.getBytes()))); // B64 encode and decode it + String f11416 = e11416.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g11416 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g11416); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01302.java b/OWASP DATASET/BenchmarkTest01302.java new file mode 100644 index 0000000000000000000000000000000000000000..abeba745c07a3ede54b2124bf15dcb459fa175e5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01302.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01302") +public class BenchmarkTest01302 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01302"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01303.java b/OWASP DATASET/BenchmarkTest01303.java new file mode 100644 index 0000000000000000000000000000000000000000..a9097e0ce171d93fff35c45270763df1dc947c93 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01303.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01303") +public class BenchmarkTest01303 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01303"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01304.java b/OWASP DATASET/BenchmarkTest01304.java new file mode 100644 index 0000000000000000000000000000000000000000..81df696a9136da61bbde406993ed43962a24dc51 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01304.java @@ -0,0 +1,90 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01304") +public class BenchmarkTest01304 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01304"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01305.java b/OWASP DATASET/BenchmarkTest01305.java new file mode 100644 index 0000000000000000000000000000000000000000..1033c2afa21f77197815fe5eb8254cb462b681f4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01305.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01305") +public class BenchmarkTest01305 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01305"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, new int[] {1, 2}); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01306.java b/OWASP DATASET/BenchmarkTest01306.java new file mode 100644 index 0000000000000000000000000000000000000000..5ccf127dea60fa7cfe6023d82a2ea828eb051ba1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01306.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01306") +public class BenchmarkTest01306 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01306"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, new String[] {"Column1", "Column2"}); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01307.java b/OWASP DATASET/BenchmarkTest01307.java new file mode 100644 index 0000000000000000000000000000000000000000..9c6785d3baadcaff60469f99ec6e5479e914062b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01307.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01307") +public class BenchmarkTest01307 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01307"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, new String[] {"Column1", "Column2"}); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01308.java b/OWASP DATASET/BenchmarkTest01308.java new file mode 100644 index 0000000000000000000000000000000000000000..311a4157952aecc2b138c001b98b1c7ce3f3609d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01308.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01308") +public class BenchmarkTest01308 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01308"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // Long results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForLong(sql); + Long results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Long.class); + response.getWriter().println("Your results are: " + String.valueOf(results)); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01309.java b/OWASP DATASET/BenchmarkTest01309.java new file mode 100644 index 0000000000000000000000000000000000000000..95128e162b9dce0257a9b6e1aab9cf354bee5182 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01309.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01309") +public class BenchmarkTest01309 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01309"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = + "SELECT TOP 1 USERNAME from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + Object results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, new Object[] {}, String.class); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(results.toString())); + // System.out.println(results.toString()); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a9334 = param; // assign + StringBuilder b9334 = new StringBuilder(a9334); // stick in stringbuilder + b9334.append(" SafeStuff"); // append some safe content + b9334.replace( + b9334.length() - "Chars".length(), + b9334.length(), + "Chars"); // replace some of the end content + java.util.HashMap map9334 = new java.util.HashMap(); + map9334.put("key9334", b9334.toString()); // put in a collection + String c9334 = (String) map9334.get("key9334"); // get it back out + String d9334 = c9334.substring(0, c9334.length() - 1); // extract most of it + String e9334 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d9334.getBytes()))); // B64 encode and decode it + String f9334 = e9334.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g9334 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g9334); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01310.java b/OWASP DATASET/BenchmarkTest01310.java new file mode 100644 index 0000000000000000000000000000000000000000..c7ea9ab13c79e1894b8991e88124e509e4388c6d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01310.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01310") +public class BenchmarkTest01310 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01310"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01311.java b/OWASP DATASET/BenchmarkTest01311.java new file mode 100644 index 0000000000000000000000000000000000000000..c0a9091848836d95b932817e54b48bf444f809d4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01311.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01311") +public class BenchmarkTest01311 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01311"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01312.java b/OWASP DATASET/BenchmarkTest01312.java new file mode 100644 index 0000000000000000000000000000000000000000..b073504092cb1a23878473a3e35419af778de2c3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01312.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01312") +public class BenchmarkTest01312 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01312"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new String[] {"username", "password"}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01313.java b/OWASP DATASET/BenchmarkTest01313.java new file mode 100644 index 0000000000000000000000000000000000000000..a7960f6ce49b4870e0afd266f512a8b1fa688205 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01313.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01313") +public class BenchmarkTest01313 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01313"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01314.java b/OWASP DATASET/BenchmarkTest01314.java new file mode 100644 index 0000000000000000000000000000000000000000..e3643925d03d58b48eff3a0c91c674c9fafa8e65 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01314.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01314") +public class BenchmarkTest01314 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01314"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01315.java b/OWASP DATASET/BenchmarkTest01315.java new file mode 100644 index 0000000000000000000000000000000000000000..9aa8acbc721772b3239a69491be8a542d57d7a7e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01315.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01315") +public class BenchmarkTest01315 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01315"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01316.java b/OWASP DATASET/BenchmarkTest01316.java new file mode 100644 index 0000000000000000000000000000000000000000..a5d41de8ffc177d2999f69e0fcbccbb056235454 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01316.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest01316") +public class BenchmarkTest01316 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest01316"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + String result = xp.evaluate(expression, xmlDocument); + + response.getWriter().println("Your query results are: " + result + "
"); + + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01317.java b/OWASP DATASET/BenchmarkTest01317.java new file mode 100644 index 0000000000000000000000000000000000000000..a702e8a51ccfa75673766cd90142a76adf7ae3e9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01317.java @@ -0,0 +1,173 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01317") +public class BenchmarkTest01317 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01317"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "DES/CBC/PKCS5PADDING", java.security.Security.getProvider("SunJCE")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01318.java b/OWASP DATASET/BenchmarkTest01318.java new file mode 100644 index 0000000000000000000000000000000000000000..c08ff0ff36b90438c84e8c80dd6f27e41e01306f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01318.java @@ -0,0 +1,184 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01318") +public class BenchmarkTest01318 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01318"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "DES/CBC/PKCS5PADDING", java.security.Security.getProvider("SunJCE")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a66881 = param; // assign + StringBuilder b66881 = new StringBuilder(a66881); // stick in stringbuilder + b66881.append(" SafeStuff"); // append some safe content + b66881.replace( + b66881.length() - "Chars".length(), + b66881.length(), + "Chars"); // replace some of the end content + java.util.HashMap map66881 = new java.util.HashMap(); + map66881.put("key66881", b66881.toString()); // put in a collection + String c66881 = (String) map66881.get("key66881"); // get it back out + String d66881 = c66881.substring(0, c66881.length() - 1); // extract most of it + String e66881 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d66881.getBytes()))); // B64 encode and decode it + String f66881 = e66881.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g66881 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g66881); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01319.java b/OWASP DATASET/BenchmarkTest01319.java new file mode 100644 index 0000000000000000000000000000000000000000..8ee13707f5c76b0c3e8bdae9bf1e16b91b5f796b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01319.java @@ -0,0 +1,166 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01319") +public class BenchmarkTest01319 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01319"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01320.java b/OWASP DATASET/BenchmarkTest01320.java new file mode 100644 index 0000000000000000000000000000000000000000..ec45ddd805bbdff69dec073b54a71c2f57477014 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01320.java @@ -0,0 +1,174 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01320") +public class BenchmarkTest01320 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01320"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01321.java b/OWASP DATASET/BenchmarkTest01321.java new file mode 100644 index 0000000000000000000000000000000000000000..ea041de408f0548c0bd2a9a0ed3673e44e9c5d5d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01321.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01321") +public class BenchmarkTest01321 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01321"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = org.owasp.benchmark.helpers.Utils.getCipher(); + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01322.java b/OWASP DATASET/BenchmarkTest01322.java new file mode 100644 index 0000000000000000000000000000000000000000..700bbc4de78c80c203534e038dc5309dd8489870 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01322.java @@ -0,0 +1,133 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01322") +public class BenchmarkTest01322 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01322"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01323.java b/OWASP DATASET/BenchmarkTest01323.java new file mode 100644 index 0000000000000000000000000000000000000000..f206c5bf537090205d8ae6be22a8359737f8ea93 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01323.java @@ -0,0 +1,138 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01323") +public class BenchmarkTest01323 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01323"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map1195 = new java.util.HashMap(); + map1195.put("keyA-1195", "a-Value"); // put some stuff in the collection + map1195.put("keyB-1195", param); // put it in a collection + map1195.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map1195.get("keyB-1195"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01324.java b/OWASP DATASET/BenchmarkTest01324.java new file mode 100644 index 0000000000000000000000000000000000000000..697d1a60fb76d50308d4df868f56dadf399c0f0d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01324.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01324") +public class BenchmarkTest01324 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01324"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "AES/CCM/NoPadding", java.security.Security.getProvider("BC")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01325.java b/OWASP DATASET/BenchmarkTest01325.java new file mode 100644 index 0000000000000000000000000000000000000000..2de5cf65b2ff78b060e7f928f2c2735a96c31280 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01325.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01325") +public class BenchmarkTest01325 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01325"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map39183 = new java.util.HashMap(); + map39183.put("keyA-39183", "a_Value"); // put some stuff in the collection + map39183.put("keyB-39183", param); // put it in a collection + map39183.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map39183.get("keyB-39183"); // get it back out + bar = (String) map39183.get("keyA-39183"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01326.java b/OWASP DATASET/BenchmarkTest01326.java new file mode 100644 index 0000000000000000000000000000000000000000..5190bcb65c7778a7aa7d1099f98075b909007866 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01326.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest01326") +public class BenchmarkTest01326 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01326"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + javax.naming.directory.DirContext ctx = ads.getDirContext(); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + bar + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + // System.out.println("Filter " + filter); + boolean found = false; + javax.naming.NamingEnumeration results = + ctx.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01327.java b/OWASP DATASET/BenchmarkTest01327.java new file mode 100644 index 0000000000000000000000000000000000000000..8190031458fba31ccfe40bda42c4917542775cac --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01327.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest01327") +public class BenchmarkTest01327 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01327"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + javax.naming.directory.DirContext ctx = ads.getDirContext(); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + bar + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + // System.out.println("Filter " + filter); + boolean found = false; + javax.naming.NamingEnumeration results = + ctx.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map41804 = new java.util.HashMap(); + map41804.put("keyA-41804", "a_Value"); // put some stuff in the collection + map41804.put("keyB-41804", param); // put it in a collection + map41804.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map41804.get("keyB-41804"); // get it back out + bar = (String) map41804.get("keyA-41804"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01328.java b/OWASP DATASET/BenchmarkTest01328.java new file mode 100644 index 0000000000000000000000000000000000000000..bfdf8f2b03844400bea161c5316fca34ccf0ab89 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01328.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01328") +public class BenchmarkTest01328 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01328"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + // FILE URIs are tricky because they are different between Mac and Windows because of lack + // of standardization. + // Mac requires an extra slash for some reason. + String startURIslashes = ""; + if (System.getProperty("os.name").indexOf("Windows") != -1) + if (System.getProperty("os.name").indexOf("Windows") != -1) startURIslashes = "/"; + else startURIslashes = "//"; + + try { + java.net.URI fileURI = + new java.net.URI( + "file:" + + startURIslashes + + org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + .replace('\\', '/') + .replace(' ', '_') + + bar); + java.io.File fileTarget = new java.io.File(fileURI); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } catch (java.net.URISyntaxException e) { + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a17973 = param; // assign + StringBuilder b17973 = new StringBuilder(a17973); // stick in stringbuilder + b17973.append(" SafeStuff"); // append some safe content + b17973.replace( + b17973.length() - "Chars".length(), + b17973.length(), + "Chars"); // replace some of the end content + java.util.HashMap map17973 = new java.util.HashMap(); + map17973.put("key17973", b17973.toString()); // put in a collection + String c17973 = (String) map17973.get("key17973"); // get it back out + String d17973 = c17973.substring(0, c17973.length() - 1); // extract most of it + String e17973 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d17973.getBytes()))); // B64 encode and decode it + String f17973 = e17973.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g17973 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g17973); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01329.java b/OWASP DATASET/BenchmarkTest01329.java new file mode 100644 index 0000000000000000000000000000000000000000..a527770422c35f4f220beff1c35dceb005bb2570 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01329.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01329") +public class BenchmarkTest01329 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01329"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + // FILE URIs are tricky because they are different between Mac and Windows because of lack + // of standardization. + // Mac requires an extra slash for some reason. + String startURIslashes = ""; + if (System.getProperty("os.name").indexOf("Windows") != -1) + if (System.getProperty("os.name").indexOf("Windows") != -1) startURIslashes = "/"; + else startURIslashes = "//"; + + try { + java.net.URI fileURI = + new java.net.URI( + "file", + null, + startURIslashes + + org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + .replace('\\', java.io.File.separatorChar) + .replace(' ', '_') + + bar, + null, + null); + java.io.File fileTarget = new java.io.File(fileURI); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } catch (java.net.URISyntaxException e) { + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01330.java b/OWASP DATASET/BenchmarkTest01330.java new file mode 100644 index 0000000000000000000000000000000000000000..f0f654f09e8e0d91b441b40b4512d605b53c6e2d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01330.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01330") +public class BenchmarkTest01330 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01330"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName)); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01331.java b/OWASP DATASET/BenchmarkTest01331.java new file mode 100644 index 0000000000000000000000000000000000000000..af3d4642b9e5ecba0b98313bd6aa5f5574bcc3c4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01331.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01331") +public class BenchmarkTest01331 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01331"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01332.java b/OWASP DATASET/BenchmarkTest01332.java new file mode 100644 index 0000000000000000000000000000000000000000..9efccdc3ad99d48135090dcbe6323dd3656f7fe0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01332.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01332") +public class BenchmarkTest01332 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01332"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = + java.security.MessageDigest.getInstance("SHA-512", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz43527 = new StringBuilder(param); + String bar = sbxyz43527.append("_SafeStuff").toString(); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01333.java b/OWASP DATASET/BenchmarkTest01333.java new file mode 100644 index 0000000000000000000000000000000000000000..fe642a065bbd6bbfb7e8951402b30706e6305e13 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01333.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01333") +public class BenchmarkTest01333 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01333"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01334.java b/OWASP DATASET/BenchmarkTest01334.java new file mode 100644 index 0000000000000000000000000000000000000000..7afdade06ab08961e1e225b0d9a1046eeffe4ef4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01334.java @@ -0,0 +1,122 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01334") +public class BenchmarkTest01334 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01334"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01335.java b/OWASP DATASET/BenchmarkTest01335.java new file mode 100644 index 0000000000000000000000000000000000000000..74311b0c978f9d0f1283186ec98e8fb49dc1c872 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01335.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01335") +public class BenchmarkTest01335 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01335"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + java.io.PrintWriter out = response.getWriter(); + out.write("\n\n\n

"); + out.format(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + out.write("\n

\n\n"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map45376 = new java.util.HashMap(); + map45376.put("keyA-45376", "a-Value"); // put some stuff in the collection + map45376.put("keyB-45376", param); // put it in a collection + map45376.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map45376.get("keyB-45376"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01336.java b/OWASP DATASET/BenchmarkTest01336.java new file mode 100644 index 0000000000000000000000000000000000000000..5bd1621a1e8e9b88a6f97e52921f6d72275c6b30 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01336.java @@ -0,0 +1,72 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01336") +public class BenchmarkTest01336 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01336"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(java.util.Locale.US, bar, obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01337.java b/OWASP DATASET/BenchmarkTest01337.java new file mode 100644 index 0000000000000000000000000000000000000000..0d70fd38974fdeff9cbad52381c131897c46dbf4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01337.java @@ -0,0 +1,68 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01337") +public class BenchmarkTest01337 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01337"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(bar, obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz24804 = new StringBuilder(param); + String bar = sbxyz24804.append("_SafeStuff").toString(); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01338.java b/OWASP DATASET/BenchmarkTest01338.java new file mode 100644 index 0000000000000000000000000000000000000000..19d39814a21c9eb7cf34bc78cc40c2aba1e9cf75 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01338.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01338") +public class BenchmarkTest01338 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01338"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar.toCharArray()); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01339.java b/OWASP DATASET/BenchmarkTest01339.java new file mode 100644 index 0000000000000000000000000000000000000000..0f667219fedc36ad2b048be5a5c6a15ab8fb28de --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01339.java @@ -0,0 +1,66 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01339") +public class BenchmarkTest01339 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01339"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar.toCharArray()); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01340.java b/OWASP DATASET/BenchmarkTest01340.java new file mode 100644 index 0000000000000000000000000000000000000000..61fbd1e3007864c043acdbab6d7cf0ad34292bb2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01340.java @@ -0,0 +1,72 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01340") +public class BenchmarkTest01340 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01340"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map36950 = new java.util.HashMap(); + map36950.put("keyA-36950", "a_Value"); // put some stuff in the collection + map36950.put("keyB-36950", param); // put it in a collection + map36950.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map36950.get("keyB-36950"); // get it back out + bar = (String) map36950.get("keyA-36950"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01341.java b/OWASP DATASET/BenchmarkTest01341.java new file mode 100644 index 0000000000000000000000000000000000000000..b11bac2b12004716ca2fe7440fb6f8e762b89c64 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01341.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01341") +public class BenchmarkTest01341 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01341"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a41908 = param; // assign + StringBuilder b41908 = new StringBuilder(a41908); // stick in stringbuilder + b41908.append(" SafeStuff"); // append some safe content + b41908.replace( + b41908.length() - "Chars".length(), + b41908.length(), + "Chars"); // replace some of the end content + java.util.HashMap map41908 = new java.util.HashMap(); + map41908.put("key41908", b41908.toString()); // put in a collection + String c41908 = (String) map41908.get("key41908"); // get it back out + String d41908 = c41908.substring(0, c41908.length() - 1); // extract most of it + String e41908 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d41908.getBytes()))); // B64 encode and decode it + String f41908 = e41908.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g41908 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g41908); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01342.java b/OWASP DATASET/BenchmarkTest01342.java new file mode 100644 index 0000000000000000000000000000000000000000..d53e4d30607cda0ceba963491bcd001ae59f58e2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01342.java @@ -0,0 +1,67 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01342") +public class BenchmarkTest01342 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01342"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01343.java b/OWASP DATASET/BenchmarkTest01343.java new file mode 100644 index 0000000000000000000000000000000000000000..d8fc4b625b926e7bac294648d5464971264491a1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01343.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01343") +public class BenchmarkTest01343 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01343"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(java.util.Locale.US, bar, obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01344.java b/OWASP DATASET/BenchmarkTest01344.java new file mode 100644 index 0000000000000000000000000000000000000000..9a10b73a798498310032c17d60560e83e4ca46cc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01344.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01344") +public class BenchmarkTest01344 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01344"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(java.util.Locale.US, bar, obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01345.java b/OWASP DATASET/BenchmarkTest01345.java new file mode 100644 index 0000000000000000000000000000000000000000..f4a746dbebd5dafede451027754930d05f113c92 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01345.java @@ -0,0 +1,71 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01345") +public class BenchmarkTest01345 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01345"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01346.java b/OWASP DATASET/BenchmarkTest01346.java new file mode 100644 index 0000000000000000000000000000000000000000..9899bff329cc7946968e78824e6a7310a9622e6e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01346.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01346") +public class BenchmarkTest01346 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01346"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01347.java b/OWASP DATASET/BenchmarkTest01347.java new file mode 100644 index 0000000000000000000000000000000000000000..5408acb82c50e4d8dde640214cc046bb317b5b7d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01347.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01347") +public class BenchmarkTest01347 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01347"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a81561 = param; // assign + StringBuilder b81561 = new StringBuilder(a81561); // stick in stringbuilder + b81561.append(" SafeStuff"); // append some safe content + b81561.replace( + b81561.length() - "Chars".length(), + b81561.length(), + "Chars"); // replace some of the end content + java.util.HashMap map81561 = new java.util.HashMap(); + map81561.put("key81561", b81561.toString()); // put in a collection + String c81561 = (String) map81561.get("key81561"); // get it back out + String d81561 = c81561.substring(0, c81561.length() - 1); // extract most of it + String e81561 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d81561.getBytes()))); // B64 encode and decode it + String f81561 = e81561.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f81561); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01348.java b/OWASP DATASET/BenchmarkTest01348.java new file mode 100644 index 0000000000000000000000000000000000000000..529c09e773fbfdb7cfecf7c80416484e03d78b63 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01348.java @@ -0,0 +1,66 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01348") +public class BenchmarkTest01348 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01348"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01349.java b/OWASP DATASET/BenchmarkTest01349.java new file mode 100644 index 0000000000000000000000000000000000000000..95c550f70e35afa3e9f3ef39ac1c5575532e01b2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01349.java @@ -0,0 +1,67 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01349") +public class BenchmarkTest01349 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01349"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz63030 = new StringBuilder(param); + String bar = sbxyz63030.append("_SafeStuff").toString(); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01350.java b/OWASP DATASET/BenchmarkTest01350.java new file mode 100644 index 0000000000000000000000000000000000000000..527911b5f90a10924b25ad9fd2b4e7e16f71a3f8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01350.java @@ -0,0 +1,72 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01350") +public class BenchmarkTest01350 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01350"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar.toCharArray(), 0, length); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01351.java b/OWASP DATASET/BenchmarkTest01351.java new file mode 100644 index 0000000000000000000000000000000000000000..9b62d8477afce1e8ee9d41ca13bffa21a694efbe --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01351.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01351") +public class BenchmarkTest01351 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01351"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar.toCharArray(), 0, length); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01352.java b/OWASP DATASET/BenchmarkTest01352.java new file mode 100644 index 0000000000000000000000000000000000000000..5ccfcc39a26835dbd511665189d627a0afb6a5c5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01352.java @@ -0,0 +1,66 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01352") +public class BenchmarkTest01352 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01352"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01353.java b/OWASP DATASET/BenchmarkTest01353.java new file mode 100644 index 0000000000000000000000000000000000000000..f26dd5cf3f7eab2294943139a37ec6405eb510fa --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01353.java @@ -0,0 +1,107 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01353") +public class BenchmarkTest01353 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01353"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(); + + pb.command(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01354.java b/OWASP DATASET/BenchmarkTest01354.java new file mode 100644 index 0000000000000000000000000000000000000000..cf862110c00602df334e95fa39e8c9b4810da49d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01354.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01354") +public class BenchmarkTest01354 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01354"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + float rand = new java.util.Random().nextFloat(); + String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "Floyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01355.java b/OWASP DATASET/BenchmarkTest01355.java new file mode 100644 index 0000000000000000000000000000000000000000..0e84dde038014f746e769f69594b89ed142d01e9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01355.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01355") +public class BenchmarkTest01355 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01355"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + float rand = new java.util.Random().nextFloat(); + String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "Floyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01356.java b/OWASP DATASET/BenchmarkTest01356.java new file mode 100644 index 0000000000000000000000000000000000000000..ab9779888deecc094d6e661584dd25cd6a4d96c7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01356.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01356") +public class BenchmarkTest01356 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01356"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + float rand = new java.util.Random().nextFloat(); + String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "Floyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01357.java b/OWASP DATASET/BenchmarkTest01357.java new file mode 100644 index 0000000000000000000000000000000000000000..ab973f3d3811200172a739825cebba9702c4a6b1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01357.java @@ -0,0 +1,118 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01357") +public class BenchmarkTest01357 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01357"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01358.java b/OWASP DATASET/BenchmarkTest01358.java new file mode 100644 index 0000000000000000000000000000000000000000..794ffd96f7da5fbbabb4f90dbba40467e2d3e0b3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01358.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01358") +public class BenchmarkTest01358 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01358"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01359.java b/OWASP DATASET/BenchmarkTest01359.java new file mode 100644 index 0000000000000000000000000000000000000000..b0321acbfe4757ccc7a3bfc56d182709bde92b83 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01359.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest01359") +public class BenchmarkTest01359 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01359"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01360.java b/OWASP DATASET/BenchmarkTest01360.java new file mode 100644 index 0000000000000000000000000000000000000000..6ff5099a7cf6bbe03cb8e149550ebdb398832d66 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01360.java @@ -0,0 +1,100 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01360") +public class BenchmarkTest01360 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01360"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01361.java b/OWASP DATASET/BenchmarkTest01361.java new file mode 100644 index 0000000000000000000000000000000000000000..ab7fc98fd3b1a148c15d8af790c0bc5a2f289971 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01361.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01361") +public class BenchmarkTest01361 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01361"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01362.java b/OWASP DATASET/BenchmarkTest01362.java new file mode 100644 index 0000000000000000000000000000000000000000..92da56d24be34e9d6ac271aae2791cef6c88cdb8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01362.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01362") +public class BenchmarkTest01362 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01362"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01363.java b/OWASP DATASET/BenchmarkTest01363.java new file mode 100644 index 0000000000000000000000000000000000000000..283542416fede86a019e2206f2247b86fc9debb9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01363.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01363") +public class BenchmarkTest01363 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01363"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01364.java b/OWASP DATASET/BenchmarkTest01364.java new file mode 100644 index 0000000000000000000000000000000000000000..8550d4407ef8d030bdcb89d8c052b3903dd07c81 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01364.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01364") +public class BenchmarkTest01364 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01364"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01365.java b/OWASP DATASET/BenchmarkTest01365.java new file mode 100644 index 0000000000000000000000000000000000000000..d25b902fee3451d2ae6e8a4a98484fe8d9542260 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01365.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01365") +public class BenchmarkTest01365 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01365"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = + r.exec(cmd + bar, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01366.java b/OWASP DATASET/BenchmarkTest01366.java new file mode 100644 index 0000000000000000000000000000000000000000..fece7998e6e544f7ba7086ac149dd0ceb1ee103c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01366.java @@ -0,0 +1,131 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01366") +public class BenchmarkTest01366 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01366"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01367.java b/OWASP DATASET/BenchmarkTest01367.java new file mode 100644 index 0000000000000000000000000000000000000000..1aacd5c19e1acbcf589087672ef1a2526d6a1a65 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01367.java @@ -0,0 +1,136 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01367") +public class BenchmarkTest01367 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01367"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01368.java b/OWASP DATASET/BenchmarkTest01368.java new file mode 100644 index 0000000000000000000000000000000000000000..c15df74c6b7e5b41b342da3f618471d259c2787a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01368.java @@ -0,0 +1,127 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01368") +public class BenchmarkTest01368 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01368"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01369.java b/OWASP DATASET/BenchmarkTest01369.java new file mode 100644 index 0000000000000000000000000000000000000000..8197eb6fbdb6bde70a743df7fd06370a137da8aa --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01369.java @@ -0,0 +1,149 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01369") +public class BenchmarkTest01369 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01369"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + getNextNumber(numGen, randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeBystander"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + void getNextNumber(java.util.Random generator, byte[] barray) { + generator.nextBytes(barray); + } + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a43860 = param; // assign + StringBuilder b43860 = new StringBuilder(a43860); // stick in stringbuilder + b43860.append(" SafeStuff"); // append some safe content + b43860.replace( + b43860.length() - "Chars".length(), + b43860.length(), + "Chars"); // replace some of the end content + java.util.HashMap map43860 = new java.util.HashMap(); + map43860.put("key43860", b43860.toString()); // put in a collection + String c43860 = (String) map43860.get("key43860"); // get it back out + String d43860 = c43860.substring(0, c43860.length() - 1); // extract most of it + String e43860 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d43860.getBytes()))); // B64 encode and decode it + String f43860 = e43860.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f43860); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01370.java b/OWASP DATASET/BenchmarkTest01370.java new file mode 100644 index 0000000000000000000000000000000000000000..befec5742d18116e56cc835d2ca373a49e598d7e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01370.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01370") +public class BenchmarkTest01370 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01370"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01371.java b/OWASP DATASET/BenchmarkTest01371.java new file mode 100644 index 0000000000000000000000000000000000000000..38a63f2e403467e6d219a89a1130e8d90f582e17 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01371.java @@ -0,0 +1,127 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01371") +public class BenchmarkTest01371 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01371"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + try { + int r = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "SafeIngrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01372.java b/OWASP DATASET/BenchmarkTest01372.java new file mode 100644 index 0000000000000000000000000000000000000000..170dce3067a5b15271b5cda05a18c0ce47ecba0a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01372.java @@ -0,0 +1,122 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01372") +public class BenchmarkTest01372 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01372"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + try { + int r = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "SafeIngrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01373.java b/OWASP DATASET/BenchmarkTest01373.java new file mode 100644 index 0000000000000000000000000000000000000000..15dd5247d54c8df147e0d2e7ab2c1c01da9d3f68 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01373.java @@ -0,0 +1,118 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01373") +public class BenchmarkTest01373 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01373"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + try { + long l = java.security.SecureRandom.getInstance("SHA1PRNG").nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "SafeLogan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextLong() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextLong() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01374.java b/OWASP DATASET/BenchmarkTest01374.java new file mode 100644 index 0000000000000000000000000000000000000000..646e9fa4ebfa859bdbf6493eea0be266109ddd44 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01374.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01374") +public class BenchmarkTest01374 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01374"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String^,java.lang.Object) + request.getSession().putValue(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: 10340 saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01375.java b/OWASP DATASET/BenchmarkTest01375.java new file mode 100644 index 0000000000000000000000000000000000000000..5ac342464897b85c7fcdb855ffa56cb3aaa89141 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01375.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01375") +public class BenchmarkTest01375 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01375"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a33070 = param; // assign + StringBuilder b33070 = new StringBuilder(a33070); // stick in stringbuilder + b33070.append(" SafeStuff"); // append some safe content + b33070.replace( + b33070.length() - "Chars".length(), + b33070.length(), + "Chars"); // replace some of the end content + java.util.HashMap map33070 = new java.util.HashMap(); + map33070.put("key33070", b33070.toString()); // put in a collection + String c33070 = (String) map33070.get("key33070"); // get it back out + String d33070 = c33070.substring(0, c33070.length() - 1); // extract most of it + String e33070 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d33070.getBytes()))); // B64 encode and decode it + String f33070 = e33070.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f33070); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01376.java b/OWASP DATASET/BenchmarkTest01376.java new file mode 100644 index 0000000000000000000000000000000000000000..02dc7b3c9548a0688d627d8d37f5bddbdde3f049 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01376.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01376") +public class BenchmarkTest01376 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01376"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01377.java b/OWASP DATASET/BenchmarkTest01377.java new file mode 100644 index 0000000000000000000000000000000000000000..0b52e39df92ad961e281b369c919612ad6f2e7dd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01377.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01377") +public class BenchmarkTest01377 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01377"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01378.java b/OWASP DATASET/BenchmarkTest01378.java new file mode 100644 index 0000000000000000000000000000000000000000..b79665d84de8a9e6b8b288c58cfe5d207c3abe71 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01378.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01378") +public class BenchmarkTest01378 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01378"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a50098 = param; // assign + StringBuilder b50098 = new StringBuilder(a50098); // stick in stringbuilder + b50098.append(" SafeStuff"); // append some safe content + b50098.replace( + b50098.length() - "Chars".length(), + b50098.length(), + "Chars"); // replace some of the end content + java.util.HashMap map50098 = new java.util.HashMap(); + map50098.put("key50098", b50098.toString()); // put in a collection + String c50098 = (String) map50098.get("key50098"); // get it back out + String d50098 = c50098.substring(0, c50098.length() - 1); // extract most of it + String e50098 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d50098.getBytes()))); // B64 encode and decode it + String f50098 = e50098.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g50098 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g50098); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01379.java b/OWASP DATASET/BenchmarkTest01379.java new file mode 100644 index 0000000000000000000000000000000000000000..9917c0bfa6ec84a988597b907ce79fa8d39377fe --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01379.java @@ -0,0 +1,93 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01379") +public class BenchmarkTest01379 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01379"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01380.java b/OWASP DATASET/BenchmarkTest01380.java new file mode 100644 index 0000000000000000000000000000000000000000..718b461575fc42b16b97831334844a20c1235294 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01380.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01380") +public class BenchmarkTest01380 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01380"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01381.java b/OWASP DATASET/BenchmarkTest01381.java new file mode 100644 index 0000000000000000000000000000000000000000..0bc4c1c2c684ddb7facaa642d29438800e8e6f49 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01381.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01381") +public class BenchmarkTest01381 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01381"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01382.java b/OWASP DATASET/BenchmarkTest01382.java new file mode 100644 index 0000000000000000000000000000000000000000..b4b3bd2f51af216c22628cd41868fb22868b801e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01382.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01382") +public class BenchmarkTest01382 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01382"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01383.java b/OWASP DATASET/BenchmarkTest01383.java new file mode 100644 index 0000000000000000000000000000000000000000..64990008b945db12577a914b4ea17faef9b739c3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01383.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01383") +public class BenchmarkTest01383 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01383"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01384.java b/OWASP DATASET/BenchmarkTest01384.java new file mode 100644 index 0000000000000000000000000000000000000000..996230e2ef61308c4b6ef5f4097484f3e1c53457 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01384.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01384") +public class BenchmarkTest01384 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01384"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, new int[] {1, 2}); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01385.java b/OWASP DATASET/BenchmarkTest01385.java new file mode 100644 index 0000000000000000000000000000000000000000..10abda1e7c7612f0c40cbaf25e4ae906777f41aa --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01385.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01385") +public class BenchmarkTest01385 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01385"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, new String[] {"Column1", "Column2"}); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01386.java b/OWASP DATASET/BenchmarkTest01386.java new file mode 100644 index 0000000000000000000000000000000000000000..8cb2c9e01800896e4fc14867f6ce0a27be010a84 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01386.java @@ -0,0 +1,93 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01386") +public class BenchmarkTest01386 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01386"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // int results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForInt(sql); + Integer results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Integer.class); + response.getWriter().println("Your results are: " + results); + // System.out.println("Your results are: " + results); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01387.java b/OWASP DATASET/BenchmarkTest01387.java new file mode 100644 index 0000000000000000000000000000000000000000..0628886c108a60f03263163b43368d6cda07b4b3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01387.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01387") +public class BenchmarkTest01387 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01387"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // int results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForInt(sql); + Integer results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Integer.class); + response.getWriter().println("Your results are: " + results); + // System.out.println("Your results are: " + results); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01388.java b/OWASP DATASET/BenchmarkTest01388.java new file mode 100644 index 0000000000000000000000000000000000000000..eb5a84876a7573b737ab21801d16331a056e1a68 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01388.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01388") +public class BenchmarkTest01388 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01388"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // int results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForInt(sql); + Integer results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Integer.class); + response.getWriter().println("Your results are: " + results); + // System.out.println("Your results are: " + results); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01389.java b/OWASP DATASET/BenchmarkTest01389.java new file mode 100644 index 0000000000000000000000000000000000000000..e26f60f017bac03dc69b953859740c1d203ed209 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01389.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-02/BenchmarkTest01389") +public class BenchmarkTest01389 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01389"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List> list = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForList(sql); + response.getWriter().println("Your results are:
"); + + // System.out.println("Your results are"); + + for (Object o : list) { + response.getWriter() + .println( + org.owasp.esapi.ESAPI.encoder().encodeForHTML(o.toString()) + + "
"); + // System.out.println(o.toString()); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01390.java b/OWASP DATASET/BenchmarkTest01390.java new file mode 100644 index 0000000000000000000000000000000000000000..4779f645584044d52e0240a48f9f78a1c4b55d5d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01390.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01390") +public class BenchmarkTest01390 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01390"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // Long results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForLong(sql); + Long results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Long.class); + response.getWriter().println("Your results are: " + String.valueOf(results)); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01391.java b/OWASP DATASET/BenchmarkTest01391.java new file mode 100644 index 0000000000000000000000000000000000000000..27ce119633806c23130b2dc602286e8a7d9d8e4f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01391.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01391") +public class BenchmarkTest01391 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01391"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + java.sql.ResultSet rs = statement.executeQuery(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map24596 = new java.util.HashMap(); + map24596.put("keyA-24596", "a-Value"); // put some stuff in the collection + map24596.put("keyB-24596", param); // put it in a collection + map24596.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map24596.get("keyB-24596"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01392.java b/OWASP DATASET/BenchmarkTest01392.java new file mode 100644 index 0000000000000000000000000000000000000000..3e0e7bb8a130328192becd7a8a346484f053366a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01392.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01392") +public class BenchmarkTest01392 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01392"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + java.sql.ResultSet rs = statement.executeQuery(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01393.java b/OWASP DATASET/BenchmarkTest01393.java new file mode 100644 index 0000000000000000000000000000000000000000..7d5f21622afeede3a35c26da2cbcb25874756f6b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01393.java @@ -0,0 +1,98 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01393") +public class BenchmarkTest01393 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01393"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a57571 = param; // assign + StringBuilder b57571 = new StringBuilder(a57571); // stick in stringbuilder + b57571.append(" SafeStuff"); // append some safe content + b57571.replace( + b57571.length() - "Chars".length(), + b57571.length(), + "Chars"); // replace some of the end content + java.util.HashMap map57571 = new java.util.HashMap(); + map57571.put("key57571", b57571.toString()); // put in a collection + String c57571 = (String) map57571.get("key57571"); // get it back out + String d57571 = c57571.substring(0, c57571.length() - 1); // extract most of it + String e57571 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d57571.getBytes()))); // B64 encode and decode it + String f57571 = e57571.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g57571 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g57571); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01394.java b/OWASP DATASET/BenchmarkTest01394.java new file mode 100644 index 0000000000000000000000000000000000000000..8eccd086d361c5e973129e462b50c7b090b4ce8e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01394.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01394") +public class BenchmarkTest01394 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01394"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01395.java b/OWASP DATASET/BenchmarkTest01395.java new file mode 100644 index 0000000000000000000000000000000000000000..427dc1fe110dd09b535b49dca26a3bdc72046acb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01395.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01395") +public class BenchmarkTest01395 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01395"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new String[] {"USERNAME", "PASSWORD"}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01396.java b/OWASP DATASET/BenchmarkTest01396.java new file mode 100644 index 0000000000000000000000000000000000000000..3bc03b236a03b3fb036b1708cb9af925550dba41 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01396.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01396") +public class BenchmarkTest01396 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01396"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new String[] {"USERNAME", "PASSWORD"}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01397.java b/OWASP DATASET/BenchmarkTest01397.java new file mode 100644 index 0000000000000000000000000000000000000000..be0c704e2ad4909c10223ae1313e8b2f4b3091a3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01397.java @@ -0,0 +1,98 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest01397") +public class BenchmarkTest01397 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest01397"); + if (values != null) param = values[0]; + } + + String bar = new Test().doSomething(request, param); + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + String result = xp.evaluate(expression, xmlDocument); + + response.getWriter().println("Your query results are: " + result + "
"); + + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01398.java b/OWASP DATASET/BenchmarkTest01398.java new file mode 100644 index 0000000000000000000000000000000000000000..f79a7a6be21dd9cdec2cacc277c0a9cac910b80d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01398.java @@ -0,0 +1,198 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01398") +public class BenchmarkTest01398 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01398")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a37227 = param; // assign + StringBuilder b37227 = new StringBuilder(a37227); // stick in stringbuilder + b37227.append(" SafeStuff"); // append some safe content + b37227.replace( + b37227.length() - "Chars".length(), + b37227.length(), + "Chars"); // replace some of the end content + java.util.HashMap map37227 = new java.util.HashMap(); + map37227.put("key37227", b37227.toString()); // put in a collection + String c37227 = (String) map37227.get("key37227"); // get it back out + String d37227 = c37227.substring(0, c37227.length() - 1); // extract most of it + String e37227 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d37227.getBytes()))); // B64 encode and decode it + String f37227 = e37227.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g37227 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g37227); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01399.java b/OWASP DATASET/BenchmarkTest01399.java new file mode 100644 index 0000000000000000000000000000000000000000..4a31a78610270538754eb3f92a6c65c5cb0db2ef --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01399.java @@ -0,0 +1,134 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01399") +public class BenchmarkTest01399 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01399")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = org.owasp.benchmark.helpers.Utils.getCipher(); + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01400.java b/OWASP DATASET/BenchmarkTest01400.java new file mode 100644 index 0000000000000000000000000000000000000000..497898c8ef8cd6b6a0d75411008db7ef4c18377b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01400.java @@ -0,0 +1,136 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01400") +public class BenchmarkTest01400 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01400")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "AES/CCM/NoPadding", java.security.Security.getProvider("BC")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01401.java b/OWASP DATASET/BenchmarkTest01401.java new file mode 100644 index 0000000000000000000000000000000000000000..be900cb26743834b1759394b4a15f43525ee8973 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01401.java @@ -0,0 +1,149 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01401") +public class BenchmarkTest01401 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01401")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + // java.security.SecureRandom random = new java.security.SecureRandom(); + // byte[] iv = random.generateSeed(16); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg2", "AES/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01402.java b/OWASP DATASET/BenchmarkTest01402.java new file mode 100644 index 0000000000000000000000000000000000000000..df7a933270a9c5e1313db251caf3c521e9eb6ec8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01402.java @@ -0,0 +1,128 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest01402") +public class BenchmarkTest01402 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01402")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + javax.naming.directory.DirContext ctx = ads.getDirContext(); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + bar + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + // System.out.println("Filter " + filter); + boolean found = false; + javax.naming.NamingEnumeration results = + ctx.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01403.java b/OWASP DATASET/BenchmarkTest01403.java new file mode 100644 index 0000000000000000000000000000000000000000..bf7a95c6ae07d70acacd22590966301643714e9a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01403.java @@ -0,0 +1,93 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01403") +public class BenchmarkTest01403 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01403")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01404.java b/OWASP DATASET/BenchmarkTest01404.java new file mode 100644 index 0000000000000000000000000000000000000000..6621640d494821109ecb188c2d73090bd88068ba --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01404.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01404") +public class BenchmarkTest01404 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01404")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + java.io.File fileTarget = new java.io.File(bar, "/Test.txt"); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a75056 = param; // assign + StringBuilder b75056 = new StringBuilder(a75056); // stick in stringbuilder + b75056.append(" SafeStuff"); // append some safe content + b75056.replace( + b75056.length() - "Chars".length(), + b75056.length(), + "Chars"); // replace some of the end content + java.util.HashMap map75056 = new java.util.HashMap(); + map75056.put("key75056", b75056.toString()); // put in a collection + String c75056 = (String) map75056.get("key75056"); // get it back out + String d75056 = c75056.substring(0, c75056.length() - 1); // extract most of it + String e75056 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d75056.getBytes()))); // B64 encode and decode it + String f75056 = e75056.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g75056 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g75056); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01405.java b/OWASP DATASET/BenchmarkTest01405.java new file mode 100644 index 0000000000000000000000000000000000000000..4463a1497c24f9f3c1a90b3624edf863e3aaed78 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01405.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01405") +public class BenchmarkTest01405 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01405")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(new java.io.File(fileName)); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting FileInputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01406.java b/OWASP DATASET/BenchmarkTest01406.java new file mode 100644 index 0000000000000000000000000000000000000000..a0def93987895fcd72e9c761b024f5ec7206e20e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01406.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01406") +public class BenchmarkTest01406 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01406")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(fileName); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01407.java b/OWASP DATASET/BenchmarkTest01407.java new file mode 100644 index 0000000000000000000000000000000000000000..ac8be5ab91ce4e5c411c090d9ec0f0a8715ca3be --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01407.java @@ -0,0 +1,100 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01407") +public class BenchmarkTest01407 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01407")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + try ( + // Create the file first so the test won't throw an exception if it doesn't exist. + // Note: Don't actually do this because this method signature could cause a tool to find + // THIS file constructor + // as a vuln, rather than the File signature we are trying to actually test. + // If necessary, just run the benchmark twice. The 1st run should create all the necessary + // files. + // new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar).createNewFile(); + + java.io.FileOutputStream fos = + new java.io.FileOutputStream(new java.io.FileInputStream(fileName).getFD()); ) { + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01408.java b/OWASP DATASET/BenchmarkTest01408.java new file mode 100644 index 0000000000000000000000000000000000000000..14aa7e6737171d8ded2d84894fca3bb109981efa --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01408.java @@ -0,0 +1,101 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01408") +public class BenchmarkTest01408 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01408")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName, false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01409.java b/OWASP DATASET/BenchmarkTest01409.java new file mode 100644 index 0000000000000000000000000000000000000000..91c608c11cdc0ba4aade2f74a0fa74ead9a8c4d1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01409.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01409") +public class BenchmarkTest01409 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01409")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + java.io.InputStream is = null; + + try { + java.nio.file.Path path = java.nio.file.Paths.get(fileName); + is = java.nio.file.Files.newInputStream(path, java.nio.file.StandardOpenOption.READ); + byte[] b = new byte[1000]; + int size = is.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + is.close(); + } catch (Exception e) { + System.out.println("Couldn't open InputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting InputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (is != null) { + try { + is.close(); + is = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map58007 = new java.util.HashMap(); + map58007.put("keyA-58007", "a_Value"); // put some stuff in the collection + map58007.put("keyB-58007", param); // put it in a collection + map58007.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map58007.get("keyB-58007"); // get it back out + bar = (String) map58007.get("keyA-58007"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01410.java b/OWASP DATASET/BenchmarkTest01410.java new file mode 100644 index 0000000000000000000000000000000000000000..dc2f92b355ce052db023a8436d2969e3c7df8057 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01410.java @@ -0,0 +1,140 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01410") +public class BenchmarkTest01410 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01410")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("sha-384", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("sha-384", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01411.java b/OWASP DATASET/BenchmarkTest01411.java new file mode 100644 index 0000000000000000000000000000000000000000..194a0666f672165805f0e12c72c6dfc1efe812f5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01411.java @@ -0,0 +1,132 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01411") +public class BenchmarkTest01411 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01411")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01412.java b/OWASP DATASET/BenchmarkTest01412.java new file mode 100644 index 0000000000000000000000000000000000000000..bbe2f235779905bea1a0448aae95968efa44018f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01412.java @@ -0,0 +1,133 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01412") +public class BenchmarkTest01412 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01412")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = + java.security.MessageDigest.getInstance("SHA-512", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01413.java b/OWASP DATASET/BenchmarkTest01413.java new file mode 100644 index 0000000000000000000000000000000000000000..46cc73c4226b85348681db571adeff1b279d310a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01413.java @@ -0,0 +1,147 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01413") +public class BenchmarkTest01413 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01413")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = + java.security.MessageDigest.getInstance("SHA-512", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01414.java b/OWASP DATASET/BenchmarkTest01414.java new file mode 100644 index 0000000000000000000000000000000000000000..c89ad3d560344210148fc99e5a82a700cb54a5c5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01414.java @@ -0,0 +1,131 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01414") +public class BenchmarkTest01414 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01414")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01415.java b/OWASP DATASET/BenchmarkTest01415.java new file mode 100644 index 0000000000000000000000000000000000000000..b5646c8ff5b25ddf551743264a6f30ea1ef1714e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01415.java @@ -0,0 +1,127 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01415") +public class BenchmarkTest01415 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01415")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01416.java b/OWASP DATASET/BenchmarkTest01416.java new file mode 100644 index 0000000000000000000000000000000000000000..927487a0c85d67ab5e9caef75a36e0068518bd27 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01416.java @@ -0,0 +1,131 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01416") +public class BenchmarkTest01416 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01416")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01417.java b/OWASP DATASET/BenchmarkTest01417.java new file mode 100644 index 0000000000000000000000000000000000000000..3ab1f0fe47027231536e856796cf22db80a98052 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01417.java @@ -0,0 +1,80 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01417") +public class BenchmarkTest01417 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01417")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + java.io.PrintWriter out = response.getWriter(); + out.write("\n\n\n

"); + out.format(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + out.write("\n

\n\n"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01418.java b/OWASP DATASET/BenchmarkTest01418.java new file mode 100644 index 0000000000000000000000000000000000000000..67f7b285390854df1826c429c1f87ea25321d5ca --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01418.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01418") +public class BenchmarkTest01418 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01418")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(java.util.Locale.US, bar, obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01419.java b/OWASP DATASET/BenchmarkTest01419.java new file mode 100644 index 0000000000000000000000000000000000000000..a1b9f23a548e9d2556e3c8b36e58c2f21801ca55 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01419.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01419") +public class BenchmarkTest01419 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01419")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().format("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01420.java b/OWASP DATASET/BenchmarkTest01420.java new file mode 100644 index 0000000000000000000000000000000000000000..818cff8a7bb28cc65d027762b3e903c26b4356b1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01420.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01420") +public class BenchmarkTest01420 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01420")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar.toCharArray()); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01421.java b/OWASP DATASET/BenchmarkTest01421.java new file mode 100644 index 0000000000000000000000000000000000000000..735fba6ddfc3c7370ce3aaf543da41e693ef4fd1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01421.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01421") +public class BenchmarkTest01421 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01421")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01422.java b/OWASP DATASET/BenchmarkTest01422.java new file mode 100644 index 0000000000000000000000000000000000000000..3f6d3ace21fc58d99df5a66713e1e3348978d3ea --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01422.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01422") +public class BenchmarkTest01422 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01422")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(java.util.Locale.US, bar, obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map80775 = new java.util.HashMap(); + map80775.put("keyA-80775", "a_Value"); // put some stuff in the collection + map80775.put("keyB-80775", param); // put it in a collection + map80775.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map80775.get("keyB-80775"); // get it back out + bar = (String) map80775.get("keyA-80775"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01423.java b/OWASP DATASET/BenchmarkTest01423.java new file mode 100644 index 0000000000000000000000000000000000000000..fa7aac4af6cb55dd392d1f04799ec3bea563c2ae --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01423.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01423") +public class BenchmarkTest01423 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01423")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {bar, "b"}; + response.getWriter().printf("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01424.java b/OWASP DATASET/BenchmarkTest01424.java new file mode 100644 index 0000000000000000000000000000000000000000..75197a2c32caeb1eade1e279a56a7bb0b3df8c34 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01424.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01424") +public class BenchmarkTest01424 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01424")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {bar, "b"}; + response.getWriter().printf("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz93549 = new StringBuilder(param); + String bar = sbxyz93549.append("_SafeStuff").toString(); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01425.java b/OWASP DATASET/BenchmarkTest01425.java new file mode 100644 index 0000000000000000000000000000000000000000..36a9b27bf289509bd381a49f26b14b1407851aaa --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01425.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01425") +public class BenchmarkTest01425 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01425")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01426.java b/OWASP DATASET/BenchmarkTest01426.java new file mode 100644 index 0000000000000000000000000000000000000000..943e2d7aa949ea0fb8423a2e45b6566e5518825b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01426.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01426") +public class BenchmarkTest01426 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01426")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01427.java b/OWASP DATASET/BenchmarkTest01427.java new file mode 100644 index 0000000000000000000000000000000000000000..4b2a062510ec9a04816cfc9832c5f0a7d5678534 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01427.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01427") +public class BenchmarkTest01427 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01427")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01428.java b/OWASP DATASET/BenchmarkTest01428.java new file mode 100644 index 0000000000000000000000000000000000000000..3e13746ddbde2003a3f01bfd5506ea045ff4da03 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01428.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01428") +public class BenchmarkTest01428 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01428")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar.toCharArray()); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01429.java b/OWASP DATASET/BenchmarkTest01429.java new file mode 100644 index 0000000000000000000000000000000000000000..2aabf4ddf8ff1c543cdc001724cef02c38616228 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01429.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01429") +public class BenchmarkTest01429 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01429")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar.toCharArray()); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01430.java b/OWASP DATASET/BenchmarkTest01430.java new file mode 100644 index 0000000000000000000000000000000000000000..3785a75bad7c5f19863280bd54b1b66bdb76a351 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01430.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01430") +public class BenchmarkTest01430 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01430")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + String a1 = ""; + String a2 = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + } else { + a1 = "sh"; + a2 = "-c"; + } + String[] args = {a1, a2, "echo " + bar}; + + ProcessBuilder pb = new ProcessBuilder(args); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.lang.String[]) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01431.java b/OWASP DATASET/BenchmarkTest01431.java new file mode 100644 index 0000000000000000000000000000000000000000..ca2adc2cdbf61b9f3acf4bf7681d3d52c4888950 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01431.java @@ -0,0 +1,122 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01431") +public class BenchmarkTest01431 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01431")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + double stuff = new java.util.Random().nextGaussian(); + String rememberMeKey = Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "Gayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter() + .println("Weak Randomness Test java.util.Random.nextGaussian() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01432.java b/OWASP DATASET/BenchmarkTest01432.java new file mode 100644 index 0000000000000000000000000000000000000000..5a649ef1e9389e5ee1564ca3ae1ceb9d27056fd6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01432.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01432") +public class BenchmarkTest01432 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01432")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + double stuff = new java.util.Random().nextGaussian(); + String rememberMeKey = Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "Gayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter() + .println("Weak Randomness Test java.util.Random.nextGaussian() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz18866 = new StringBuilder(param); + bar = + sbxyz18866 + .replace(param.length() - "Z".length(), param.length(), "Z") + .toString(); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01433.java b/OWASP DATASET/BenchmarkTest01433.java new file mode 100644 index 0000000000000000000000000000000000000000..a2bb5ddc3307ad75e77a0fc30eb53d7ec8d5007a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01433.java @@ -0,0 +1,126 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01433") +public class BenchmarkTest01433 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01433")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + int randNumber = new java.util.Random().nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "Inga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt(int) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01434.java b/OWASP DATASET/BenchmarkTest01434.java new file mode 100644 index 0000000000000000000000000000000000000000..59e5e98f59c3bacb3566b126f35daa1474b3ce44 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01434.java @@ -0,0 +1,126 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01434") +public class BenchmarkTest01434 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01434")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01435.java b/OWASP DATASET/BenchmarkTest01435.java new file mode 100644 index 0000000000000000000000000000000000000000..270baddbacfcb56c49394f8a5767439845c6b006 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01435.java @@ -0,0 +1,122 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01435") +public class BenchmarkTest01435 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01435")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01436.java b/OWASP DATASET/BenchmarkTest01436.java new file mode 100644 index 0000000000000000000000000000000000000000..cf1c32f422fc9cdb01afad17e96a5b8abd23ceed --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01436.java @@ -0,0 +1,107 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest01436") +public class BenchmarkTest01436 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01436")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01437.java b/OWASP DATASET/BenchmarkTest01437.java new file mode 100644 index 0000000000000000000000000000000000000000..b65ac071f5fc3b1dbfd9b102d0bf4076efe871a5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01437.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01437") +public class BenchmarkTest01437 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01437")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write("Parameter value: " + bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01438.java b/OWASP DATASET/BenchmarkTest01438.java new file mode 100644 index 0000000000000000000000000000000000000000..7e8d9a22b4728b45907aae7280833d6f52b2f40e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01438.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01438") +public class BenchmarkTest01438 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01438")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write("Parameter value: " + bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a32762 = param; // assign + StringBuilder b32762 = new StringBuilder(a32762); // stick in stringbuilder + b32762.append(" SafeStuff"); // append some safe content + b32762.replace( + b32762.length() - "Chars".length(), + b32762.length(), + "Chars"); // replace some of the end content + java.util.HashMap map32762 = new java.util.HashMap(); + map32762.put("key32762", b32762.toString()); // put in a collection + String c32762 = (String) map32762.get("key32762"); // get it back out + String d32762 = c32762.substring(0, c32762.length() - 1); // extract most of it + String e32762 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d32762.getBytes()))); // B64 encode and decode it + String f32762 = e32762.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f32762); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01439.java b/OWASP DATASET/BenchmarkTest01439.java new file mode 100644 index 0000000000000000000000000000000000000000..27d0c755952407c3d06000317d3d4d426064a47b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01439.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01439") +public class BenchmarkTest01439 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01439")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write("Parameter value: " + bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map95590 = new java.util.HashMap(); + map95590.put("keyA-95590", "a_Value"); // put some stuff in the collection + map95590.put("keyB-95590", param); // put it in a collection + map95590.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map95590.get("keyB-95590"); // get it back out + bar = (String) map95590.get("keyA-95590"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01440.java b/OWASP DATASET/BenchmarkTest01440.java new file mode 100644 index 0000000000000000000000000000000000000000..46d93a6124459cdf929cf676bbac3fa5732f2700 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01440.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01440") +public class BenchmarkTest01440 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01440")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01441.java b/OWASP DATASET/BenchmarkTest01441.java new file mode 100644 index 0000000000000000000000000000000000000000..d0170018ff952754817eaf1c42b13bb2ba23bda0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01441.java @@ -0,0 +1,105 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01441") +public class BenchmarkTest01441 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01441")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ping -c1 "); + args = new String[] {a1, a2, cmd + bar}; + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01442.java b/OWASP DATASET/BenchmarkTest01442.java new file mode 100644 index 0000000000000000000000000000000000000000..b5511659b5710ca75265da3523ac81fe6a621a5b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01442.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01442") +public class BenchmarkTest01442 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01442")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01443.java b/OWASP DATASET/BenchmarkTest01443.java new file mode 100644 index 0000000000000000000000000000000000000000..b2744d912da6482eee562346567b8f85833e2c74 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01443.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01443") +public class BenchmarkTest01443 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01443")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01444.java b/OWASP DATASET/BenchmarkTest01444.java new file mode 100644 index 0000000000000000000000000000000000000000..b286485e19142eeec230dc0cdc13bbd134980fdc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01444.java @@ -0,0 +1,100 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01444") +public class BenchmarkTest01444 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01444")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01445.java b/OWASP DATASET/BenchmarkTest01445.java new file mode 100644 index 0000000000000000000000000000000000000000..bdae8cb9e947bbd6114601c41bfee804e34bec3c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01445.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01445") +public class BenchmarkTest01445 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01445")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map3083 = new java.util.HashMap(); + map3083.put("keyA-3083", "a_Value"); // put some stuff in the collection + map3083.put("keyB-3083", param); // put it in a collection + map3083.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map3083.get("keyB-3083"); // get it back out + bar = (String) map3083.get("keyA-3083"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01446.java b/OWASP DATASET/BenchmarkTest01446.java new file mode 100644 index 0000000000000000000000000000000000000000..32fc204597e48c2e73749f41ccd5288f05249c14 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01446.java @@ -0,0 +1,100 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01446") +public class BenchmarkTest01446 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01446")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = + r.exec(cmd + bar, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01447.java b/OWASP DATASET/BenchmarkTest01447.java new file mode 100644 index 0000000000000000000000000000000000000000..5e4c1b4ea562ac44e2315446e0ec5d60078e529b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01447.java @@ -0,0 +1,149 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01447") +public class BenchmarkTest01447 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01447")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + getNextNumber(numGen, randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeBystander"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + void getNextNumber(java.util.Random generator, byte[] barray) { + generator.nextBytes(barray); + } + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01448.java b/OWASP DATASET/BenchmarkTest01448.java new file mode 100644 index 0000000000000000000000000000000000000000..f4647845d7fab2e0c22bbb3aa2391b6c2310c42c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01448.java @@ -0,0 +1,135 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01448") +public class BenchmarkTest01448 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01448")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01449.java b/OWASP DATASET/BenchmarkTest01449.java new file mode 100644 index 0000000000000000000000000000000000000000..9eca5369853a289838ceb465047383ef94407f70 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01449.java @@ -0,0 +1,142 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01449") +public class BenchmarkTest01449 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01449")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + double rand = getNextNumber(numGen); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonatella"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + double getNextNumber(java.util.Random generator) { + return generator.nextDouble(); + } + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01450.java b/OWASP DATASET/BenchmarkTest01450.java new file mode 100644 index 0000000000000000000000000000000000000000..4f3ed3d9add79dd7acaa52e479d9b257692cbb92 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01450.java @@ -0,0 +1,142 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01450") +public class BenchmarkTest01450 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01450")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map75877 = new java.util.HashMap(); + map75877.put("keyA-75877", "a_Value"); // put some stuff in the collection + map75877.put("keyB-75877", param); // put it in a collection + map75877.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map75877.get("keyB-75877"); // get it back out + bar = (String) map75877.get("keyA-75877"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01451.java b/OWASP DATASET/BenchmarkTest01451.java new file mode 100644 index 0000000000000000000000000000000000000000..cc1378dddfe252158fae943c21d4bfe4c7028f51 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01451.java @@ -0,0 +1,147 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01451") +public class BenchmarkTest01451 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01451")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + float rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextFloat(); + String rememberMeKey = + Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeFloyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextFloat() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextFloat() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01452.java b/OWASP DATASET/BenchmarkTest01452.java new file mode 100644 index 0000000000000000000000000000000000000000..e425f02f23f8900cbbd591ff047849e4a8c9e975 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01452.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01452") +public class BenchmarkTest01452 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01452")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + double stuff = java.security.SecureRandom.getInstance("SHA1PRNG").nextGaussian(); + String rememberMeKey = + Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "SafeGayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextGaussian() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextGaussian() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01453.java b/OWASP DATASET/BenchmarkTest01453.java new file mode 100644 index 0000000000000000000000000000000000000000..65a130c20c4523a5dd0f784fdf41fc380e55ccf0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01453.java @@ -0,0 +1,127 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01453") +public class BenchmarkTest01453 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01453")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + int randNumber = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "SafeInga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt(int) - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt(int) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01454.java b/OWASP DATASET/BenchmarkTest01454.java new file mode 100644 index 0000000000000000000000000000000000000000..1753dcbe8bfb1fd3cebfc4cf0b9bdc26483be81b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01454.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01454") +public class BenchmarkTest01454 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01454")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01455.java b/OWASP DATASET/BenchmarkTest01455.java new file mode 100644 index 0000000000000000000000000000000000000000..96dcc9be934411e08310f33a482923808c3cfd58 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01455.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01455") +public class BenchmarkTest01455 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01455")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01456.java b/OWASP DATASET/BenchmarkTest01456.java new file mode 100644 index 0000000000000000000000000000000000000000..a3ad1fbe2b301e234798d655c4b66662ae33ed42 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01456.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01456") +public class BenchmarkTest01456 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01456")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01457.java b/OWASP DATASET/BenchmarkTest01457.java new file mode 100644 index 0000000000000000000000000000000000000000..c7c1fd81df0b6799151259232948d8be866f3c99 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01457.java @@ -0,0 +1,101 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01457") +public class BenchmarkTest01457 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01457")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01458.java b/OWASP DATASET/BenchmarkTest01458.java new file mode 100644 index 0000000000000000000000000000000000000000..b6cced11253e1d3bdc675e4e201bbbf75844bab4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01458.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01458") +public class BenchmarkTest01458 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01458")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String^,java.lang.Object) + request.getSession().setAttribute(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: '10340' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a34936 = param; // assign + StringBuilder b34936 = new StringBuilder(a34936); // stick in stringbuilder + b34936.append(" SafeStuff"); // append some safe content + b34936.replace( + b34936.length() - "Chars".length(), + b34936.length(), + "Chars"); // replace some of the end content + java.util.HashMap map34936 = new java.util.HashMap(); + map34936.put("key34936", b34936.toString()); // put in a collection + String c34936 = (String) map34936.get("key34936"); // get it back out + String d34936 = c34936.substring(0, c34936.length() - 1); // extract most of it + String e34936 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d34936.getBytes()))); // B64 encode and decode it + String f34936 = e34936.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f34936); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01459.java b/OWASP DATASET/BenchmarkTest01459.java new file mode 100644 index 0000000000000000000000000000000000000000..c18df748546d7ce3e4348361556f20556ca0ae51 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01459.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01459") +public class BenchmarkTest01459 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01459")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = connection.prepareCall(sql); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01460.java b/OWASP DATASET/BenchmarkTest01460.java new file mode 100644 index 0000000000000000000000000000000000000000..9bff7da7620ba3525be6211a66feebd3863d6f04 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01460.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01460") +public class BenchmarkTest01460 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01460")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map72098 = new java.util.HashMap(); + map72098.put("keyA-72098", "a-Value"); // put some stuff in the collection + map72098.put("keyB-72098", param); // put it in a collection + map72098.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map72098.get("keyB-72098"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01461.java b/OWASP DATASET/BenchmarkTest01461.java new file mode 100644 index 0000000000000000000000000000000000000000..98472724a141c46554b99db8e13b78966476def7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01461.java @@ -0,0 +1,98 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01461") +public class BenchmarkTest01461 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01461")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map96401 = new java.util.HashMap(); + map96401.put("keyA-96401", "a_Value"); // put some stuff in the collection + map96401.put("keyB-96401", param); // put it in a collection + map96401.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map96401.get("keyB-96401"); // get it back out + bar = (String) map96401.get("keyA-96401"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01462.java b/OWASP DATASET/BenchmarkTest01462.java new file mode 100644 index 0000000000000000000000000000000000000000..ba8981e8176fb33a9351bef2ee873698556a17d6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01462.java @@ -0,0 +1,93 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01462") +public class BenchmarkTest01462 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01462")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01463.java b/OWASP DATASET/BenchmarkTest01463.java new file mode 100644 index 0000000000000000000000000000000000000000..43c8d6aafacaca25207dfb6dab2145bd472c01b5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01463.java @@ -0,0 +1,98 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01463") +public class BenchmarkTest01463 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01463")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01464.java b/OWASP DATASET/BenchmarkTest01464.java new file mode 100644 index 0000000000000000000000000000000000000000..44db231f40588a100e311a17d4eac8bfc2827490 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01464.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01464") +public class BenchmarkTest01464 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01464")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01465.java b/OWASP DATASET/BenchmarkTest01465.java new file mode 100644 index 0000000000000000000000000000000000000000..ed146cd715d7e62f3f5c7518932bfac282b1f97c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01465.java @@ -0,0 +1,100 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01465") +public class BenchmarkTest01465 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01465")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.execute(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring execute method doesn't return results."); + + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01466.java b/OWASP DATASET/BenchmarkTest01466.java new file mode 100644 index 0000000000000000000000000000000000000000..624db13c539bcd5a076d1e404e9c4a4f116cd259 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01466.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01466") +public class BenchmarkTest01466 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01466")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.query( + sql, + new org.springframework.jdbc.core.RowMapper() { + @Override + public String mapRow(java.sql.ResultSet rs, int rowNum) + throws java.sql.SQLException { + try { + return rs.getString("USERNAME"); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper + .hideSQLErrors) { + return "Error processing query."; + } else throw e; + } + } + }); + response.getWriter().println("Your results are: "); + + for (String s : results) { + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(s) + "
"); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01467.java b/OWASP DATASET/BenchmarkTest01467.java new file mode 100644 index 0000000000000000000000000000000000000000..d1c7dfa97b8a21ded2c0219424cfd6d0dfa71e52 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01467.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01467") +public class BenchmarkTest01467 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01467")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List> list = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForList(sql); + response.getWriter().println("Your results are:
"); + + // System.out.println("Your results are"); + + for (Object o : list) { + response.getWriter() + .println( + org.owasp.esapi.ESAPI.encoder().encodeForHTML(o.toString()) + + "
"); + // System.out.println(o.toString()); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map34856 = new java.util.HashMap(); + map34856.put("keyA-34856", "a_Value"); // put some stuff in the collection + map34856.put("keyB-34856", param); // put it in a collection + map34856.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map34856.get("keyB-34856"); // get it back out + bar = (String) map34856.get("keyA-34856"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01468.java b/OWASP DATASET/BenchmarkTest01468.java new file mode 100644 index 0000000000000000000000000000000000000000..6dbb3e4359d5f8b202431d974ea95a90332b6627 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01468.java @@ -0,0 +1,105 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01468") +public class BenchmarkTest01468 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01468")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List> list = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForList(sql); + response.getWriter().println("Your results are:
"); + + // System.out.println("Your results are"); + + for (Object o : list) { + response.getWriter() + .println( + org.owasp.esapi.ESAPI.encoder().encodeForHTML(o.toString()) + + "
"); + // System.out.println(o.toString()); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01469.java b/OWASP DATASET/BenchmarkTest01469.java new file mode 100644 index 0000000000000000000000000000000000000000..d81ecd17073db63ec875dee133ec0b90a9100b8c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01469.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01469") +public class BenchmarkTest01469 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01469")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List> list = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForList(sql); + response.getWriter().println("Your results are:
"); + + // System.out.println("Your results are"); + + for (Object o : list) { + response.getWriter() + .println( + org.owasp.esapi.ESAPI.encoder().encodeForHTML(o.toString()) + + "
"); + // System.out.println(o.toString()); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a83916 = param; // assign + StringBuilder b83916 = new StringBuilder(a83916); // stick in stringbuilder + b83916.append(" SafeStuff"); // append some safe content + b83916.replace( + b83916.length() - "Chars".length(), + b83916.length(), + "Chars"); // replace some of the end content + java.util.HashMap map83916 = new java.util.HashMap(); + map83916.put("key83916", b83916.toString()); // put in a collection + String c83916 = (String) map83916.get("key83916"); // get it back out + String d83916 = c83916.substring(0, c83916.length() - 1); // extract most of it + String e83916 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d83916.getBytes()))); // B64 encode and decode it + String f83916 = e83916.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g83916 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g83916); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01470.java b/OWASP DATASET/BenchmarkTest01470.java new file mode 100644 index 0000000000000000000000000000000000000000..cbd399a96432309f19f861ea3ff793b5dcf7adb5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01470.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01470") +public class BenchmarkTest01470 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01470")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = + "SELECT TOP 1 userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.Map results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForMap(sql); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(results.toString())); + // System.out.println(results.toString()); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01471.java b/OWASP DATASET/BenchmarkTest01471.java new file mode 100644 index 0000000000000000000000000000000000000000..92ff4a94552d88a63f9b1227256ab8702cbefba9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01471.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01471") +public class BenchmarkTest01471 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01471")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01472.java b/OWASP DATASET/BenchmarkTest01472.java new file mode 100644 index 0000000000000000000000000000000000000000..b5c87b7b3d9046b2b7789bf53ef94d93e59c10a2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01472.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01472") +public class BenchmarkTest01472 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01472")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.addBatch(sql); + int[] counts = statement.executeBatch(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(sql, counts, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a60049 = param; // assign + StringBuilder b60049 = new StringBuilder(a60049); // stick in stringbuilder + b60049.append(" SafeStuff"); // append some safe content + b60049.replace( + b60049.length() - "Chars".length(), + b60049.length(), + "Chars"); // replace some of the end content + java.util.HashMap map60049 = new java.util.HashMap(); + map60049.put("key60049", b60049.toString()); // put in a collection + String c60049 = (String) map60049.get("key60049"); // get it back out + String d60049 = c60049.substring(0, c60049.length() - 1); // extract most of it + String e60049 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d60049.getBytes()))); // B64 encode and decode it + String f60049 = e60049.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g60049 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g60049); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01473.java b/OWASP DATASET/BenchmarkTest01473.java new file mode 100644 index 0000000000000000000000000000000000000000..c7807549085c33e7dea53a1a4980927a2b548dac --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01473.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01473") +public class BenchmarkTest01473 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01473")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01474.java b/OWASP DATASET/BenchmarkTest01474.java new file mode 100644 index 0000000000000000000000000000000000000000..6a991c82bd2c17b234cc887936e438e49702d4a8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01474.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01474") +public class BenchmarkTest01474 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01474")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01475.java b/OWASP DATASET/BenchmarkTest01475.java new file mode 100644 index 0000000000000000000000000000000000000000..a6544d1b0d0bb2f697a46508b904d4bd6d939051 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01475.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01475") +public class BenchmarkTest01475 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01475")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01476.java b/OWASP DATASET/BenchmarkTest01476.java new file mode 100644 index 0000000000000000000000000000000000000000..6bb213696e203e321f392a38947ef6f11c4ce53f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01476.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01476") +public class BenchmarkTest01476 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01476")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new String[] {"USERNAME", "PASSWORD"}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01477.java b/OWASP DATASET/BenchmarkTest01477.java new file mode 100644 index 0000000000000000000000000000000000000000..cde5f9c9df53cf94475410506edf11ae39adb1ba --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01477.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01477") +public class BenchmarkTest01477 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01477")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new String[] {"USERNAME", "PASSWORD"}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01478.java b/OWASP DATASET/BenchmarkTest01478.java new file mode 100644 index 0000000000000000000000000000000000000000..954fc12b3dd1076c4b0ac0181cf34d082158aa39 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01478.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest01478") +public class BenchmarkTest01478 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01478")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + org.w3c.dom.NodeList nodeList = + (org.w3c.dom.NodeList) + xp.compile(expression) + .evaluate(xmlDocument, javax.xml.xpath.XPathConstants.NODESET); + + response.getWriter().println("Your query results are:
"); + + for (int i = 0; i < nodeList.getLength(); i++) { + org.w3c.dom.Element value = (org.w3c.dom.Element) nodeList.item(i); + response.getWriter().println(value.getTextContent() + "
"); + } + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01479.java b/OWASP DATASET/BenchmarkTest01479.java new file mode 100644 index 0000000000000000000000000000000000000000..5be03289440d1ac859791c439009c01ca8355557 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01479.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest01479") +public class BenchmarkTest01479 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest01479")) { + param = name; + flag = false; + } + } + } + } + + String bar = new Test().doSomething(request, param); + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + org.w3c.dom.NodeList nodeList = + (org.w3c.dom.NodeList) + xp.compile(expression) + .evaluate(xmlDocument, javax.xml.xpath.XPathConstants.NODESET); + + response.getWriter().println("Your query results are:
"); + + for (int i = 0; i < nodeList.getLength(); i++) { + org.w3c.dom.Element value = (org.w3c.dom.Element) nodeList.item(i); + response.getWriter().println(value.getTextContent() + "
"); + } + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01480.java b/OWASP DATASET/BenchmarkTest01480.java new file mode 100644 index 0000000000000000000000000000000000000000..0e8b4f57b8039beee4500557034151bc6774ead3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01480.java @@ -0,0 +1,181 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01480") +public class BenchmarkTest01480 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01480"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "DES/CBC/PKCS5PADDING", java.security.Security.getProvider("SunJCE")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a55670 = param; // assign + StringBuilder b55670 = new StringBuilder(a55670); // stick in stringbuilder + b55670.append(" SafeStuff"); // append some safe content + b55670.replace( + b55670.length() - "Chars".length(), + b55670.length(), + "Chars"); // replace some of the end content + java.util.HashMap map55670 = new java.util.HashMap(); + map55670.put("key55670", b55670.toString()); // put in a collection + String c55670 = (String) map55670.get("key55670"); // get it back out + String d55670 = c55670.substring(0, c55670.length() - 1); // extract most of it + String e55670 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d55670.getBytes()))); // B64 encode and decode it + String f55670 = e55670.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f55670); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01481.java b/OWASP DATASET/BenchmarkTest01481.java new file mode 100644 index 0000000000000000000000000000000000000000..012174b2d6f6c778f58ee4dfb84d506fcf49afbe --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01481.java @@ -0,0 +1,168 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01481") +public class BenchmarkTest01481 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01481"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map69587 = new java.util.HashMap(); + map69587.put("keyA-69587", "a_Value"); // put some stuff in the collection + map69587.put("keyB-69587", param); // put it in a collection + map69587.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map69587.get("keyB-69587"); // get it back out + bar = (String) map69587.get("keyA-69587"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01482.java b/OWASP DATASET/BenchmarkTest01482.java new file mode 100644 index 0000000000000000000000000000000000000000..ee85786cc03fdb351fe0ecf8ea45f7aed1865b84 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01482.java @@ -0,0 +1,181 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01482") +public class BenchmarkTest01482 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01482"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01483.java b/OWASP DATASET/BenchmarkTest01483.java new file mode 100644 index 0000000000000000000000000000000000000000..a9dd9f76949e9dcb02dc3e3808eec9df6425d46a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01483.java @@ -0,0 +1,175 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01483") +public class BenchmarkTest01483 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01483"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01484.java b/OWASP DATASET/BenchmarkTest01484.java new file mode 100644 index 0000000000000000000000000000000000000000..723f77504887c2a180adba043c82b9e0889632c1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01484.java @@ -0,0 +1,166 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01484") +public class BenchmarkTest01484 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01484"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01485.java b/OWASP DATASET/BenchmarkTest01485.java new file mode 100644 index 0000000000000000000000000000000000000000..6b6731e9f238491f0fbdc0ef08e23df572516156 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01485.java @@ -0,0 +1,131 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01485") +public class BenchmarkTest01485 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01485"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = org.owasp.benchmark.helpers.Utils.getCipher(); + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01486.java b/OWASP DATASET/BenchmarkTest01486.java new file mode 100644 index 0000000000000000000000000000000000000000..4156ef3dc5f000a2aa1443f1f7df0a152e1f1be3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01486.java @@ -0,0 +1,134 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01486") +public class BenchmarkTest01486 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01486"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01487.java b/OWASP DATASET/BenchmarkTest01487.java new file mode 100644 index 0000000000000000000000000000000000000000..08ae77f7ebfae343017be035c23c111c483b4501 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01487.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01487") +public class BenchmarkTest01487 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01487"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "AES/CCM/NoPadding", java.security.Security.getProvider("BC")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map78614 = new java.util.HashMap(); + map78614.put("keyA-78614", "a_Value"); // put some stuff in the collection + map78614.put("keyB-78614", param); // put it in a collection + map78614.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map78614.get("keyB-78614"); // get it back out + bar = (String) map78614.get("keyA-78614"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01488.java b/OWASP DATASET/BenchmarkTest01488.java new file mode 100644 index 0000000000000000000000000000000000000000..6c9f01de93fe6fea1f1805a4c649dce7997bf37f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01488.java @@ -0,0 +1,126 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01488") +public class BenchmarkTest01488 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01488"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "AES/CCM/NoPadding", java.security.Security.getProvider("BC")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01489.java b/OWASP DATASET/BenchmarkTest01489.java new file mode 100644 index 0000000000000000000000000000000000000000..7354c5c7d9140ea5de63ba3ff29d7dc3cced2fc2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01489.java @@ -0,0 +1,127 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01489") +public class BenchmarkTest01489 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01489"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01490.java b/OWASP DATASET/BenchmarkTest01490.java new file mode 100644 index 0000000000000000000000000000000000000000..c29131fe730eb7a911a39fcd2d21bc7788d0197b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01490.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest01490") +public class BenchmarkTest01490 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01490"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + javax.naming.directory.DirContext ctx = ads.getDirContext(); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + bar + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + // System.out.println("Filter " + filter); + boolean found = false; + javax.naming.NamingEnumeration results = + ctx.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map58491 = new java.util.HashMap(); + map58491.put("keyA-58491", "a-Value"); // put some stuff in the collection + map58491.put("keyB-58491", param); // put it in a collection + map58491.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map58491.get("keyB-58491"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01491.java b/OWASP DATASET/BenchmarkTest01491.java new file mode 100644 index 0000000000000000000000000000000000000000..e1ec9a6a3371f57163cd42c903cf02fdb1e68e57 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01491.java @@ -0,0 +1,131 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest01491") +public class BenchmarkTest01491 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01491"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + javax.naming.directory.DirContext ctx = ads.getDirContext(); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person)(uid=" + bar + "))"; + // System.out.println("Filter " + filter); + boolean found = false; + javax.naming.NamingEnumeration results = + ctx.search(base, filter, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a55812 = param; // assign + StringBuilder b55812 = new StringBuilder(a55812); // stick in stringbuilder + b55812.append(" SafeStuff"); // append some safe content + b55812.replace( + b55812.length() - "Chars".length(), + b55812.length(), + "Chars"); // replace some of the end content + java.util.HashMap map55812 = new java.util.HashMap(); + map55812.put("key55812", b55812.toString()); // put in a collection + String c55812 = (String) map55812.get("key55812"); // get it back out + String d55812 = c55812.substring(0, c55812.length() - 1); // extract most of it + String e55812 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d55812.getBytes()))); // B64 encode and decode it + String f55812 = e55812.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g55812 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g55812); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01492.java b/OWASP DATASET/BenchmarkTest01492.java new file mode 100644 index 0000000000000000000000000000000000000000..1b92dadc985704c72b5cec86ebc228e307a007a6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01492.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest01492") +public class BenchmarkTest01492 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01492"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + javax.naming.directory.DirContext ctx = ads.getDirContext(); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person)(uid=" + bar + "))"; + // System.out.println("Filter " + filter); + boolean found = false; + javax.naming.NamingEnumeration results = + ctx.search(base, filter, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01493.java b/OWASP DATASET/BenchmarkTest01493.java new file mode 100644 index 0000000000000000000000000000000000000000..3949a4431b45c5cc1b2790d3c68ab7234803a15a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01493.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01493") +public class BenchmarkTest01493 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01493"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map71009 = new java.util.HashMap(); + map71009.put("keyA-71009", "a_Value"); // put some stuff in the collection + map71009.put("keyB-71009", param); // put it in a collection + map71009.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map71009.get("keyB-71009"); // get it back out + bar = (String) map71009.get("keyA-71009"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01494.java b/OWASP DATASET/BenchmarkTest01494.java new file mode 100644 index 0000000000000000000000000000000000000000..f0f522a23d889939ba4fb5efc203250717b38bff --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01494.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01494") +public class BenchmarkTest01494 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01494"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + java.io.File fileTarget = + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR, bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01495.java b/OWASP DATASET/BenchmarkTest01495.java new file mode 100644 index 0000000000000000000000000000000000000000..5e12b7cac5ae7091fa14fade410246472106de7c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01495.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01495") +public class BenchmarkTest01495 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01495"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + // FILE URIs are tricky because they are different between Mac and Windows because of lack + // of standardization. + // Mac requires an extra slash for some reason. + String startURIslashes = ""; + if (System.getProperty("os.name").indexOf("Windows") != -1) + if (System.getProperty("os.name").indexOf("Windows") != -1) startURIslashes = "/"; + else startURIslashes = "//"; + + try { + java.net.URI fileURI = + new java.net.URI( + "file", + null, + startURIslashes + + org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + .replace('\\', java.io.File.separatorChar) + .replace(' ', '_') + + bar, + null, + null); + java.io.File fileTarget = new java.io.File(fileURI); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } catch (java.net.URISyntaxException e) { + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01496.java b/OWASP DATASET/BenchmarkTest01496.java new file mode 100644 index 0000000000000000000000000000000000000000..6875fba2fe2716215297d3820a4af2207b39d03b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01496.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01496") +public class BenchmarkTest01496 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01496"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(fileName); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01497.java b/OWASP DATASET/BenchmarkTest01497.java new file mode 100644 index 0000000000000000000000000000000000000000..ba147afec98e9fd8a1e9859040189064f546b4a8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01497.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01497") +public class BenchmarkTest01497 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01497"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName)); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01498.java b/OWASP DATASET/BenchmarkTest01498.java new file mode 100644 index 0000000000000000000000000000000000000000..931d166cc8dd4bfd77b39268529ebb3d0f3a64bf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01498.java @@ -0,0 +1,90 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01498") +public class BenchmarkTest01498 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01498"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + try ( + // Create the file first so the test won't throw an exception if it doesn't exist. + // Note: Don't actually do this because this method signature could cause a tool to find + // THIS file constructor + // as a vuln, rather than the File signature we are trying to actually test. + // If necessary, just run the benchmark twice. The 1st run should create all the necessary + // files. + // new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar).createNewFile(); + + java.io.FileOutputStream fos = + new java.io.FileOutputStream(new java.io.FileInputStream(fileName).getFD()); ) { + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01499.java b/OWASP DATASET/BenchmarkTest01499.java new file mode 100644 index 0000000000000000000000000000000000000000..98625b644fe38426e613b300c79d60dd117642db --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01499.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01499") +public class BenchmarkTest01499 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01499"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName, false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01500.java b/OWASP DATASET/BenchmarkTest01500.java new file mode 100644 index 0000000000000000000000000000000000000000..c437f430682e5d0080a7125375e8578f13342c7f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01500.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01500") +public class BenchmarkTest01500 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01500"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + java.io.InputStream is = null; + + try { + java.nio.file.Path path = java.nio.file.Paths.get(fileName); + is = java.nio.file.Files.newInputStream(path, java.nio.file.StandardOpenOption.READ); + byte[] b = new byte[1000]; + int size = is.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + is.close(); + } catch (Exception e) { + System.out.println("Couldn't open InputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting InputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (is != null) { + try { + is.close(); + is = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map3545 = new java.util.HashMap(); + map3545.put("keyA-3545", "a-Value"); // put some stuff in the collection + map3545.put("keyB-3545", param); // put it in a collection + map3545.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map3545.get("keyB-3545"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01501.java b/OWASP DATASET/BenchmarkTest01501.java new file mode 100644 index 0000000000000000000000000000000000000000..9a894e761bfa7d2738cace47c7e6c9d9a9f1de49 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01501.java @@ -0,0 +1,123 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest01501") +public class BenchmarkTest01501 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01501"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person)(uid=" + bar + "))"; + + javax.naming.directory.DirContext ctx = ads.getDirContext(); + javax.naming.directory.InitialDirContext idc = + (javax.naming.directory.InitialDirContext) ctx; + boolean found = false; + javax.naming.NamingEnumeration results = + idc.search(base, filter, sc); + + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01502.java b/OWASP DATASET/BenchmarkTest01502.java new file mode 100644 index 0000000000000000000000000000000000000000..26ebc0345e29027909917d7807c8c8dbd7c68712 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01502.java @@ -0,0 +1,131 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01502") +public class BenchmarkTest01502 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01502"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + double value = java.lang.Math.random(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Doug"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + response.getWriter().println("Weak Randomness Test java.lang.Math.random() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a43640 = param; // assign + StringBuilder b43640 = new StringBuilder(a43640); // stick in stringbuilder + b43640.append(" SafeStuff"); // append some safe content + b43640.replace( + b43640.length() - "Chars".length(), + b43640.length(), + "Chars"); // replace some of the end content + java.util.HashMap map43640 = new java.util.HashMap(); + map43640.put("key43640", b43640.toString()); // put in a collection + String c43640 = (String) map43640.get("key43640"); // get it back out + String d43640 = c43640.substring(0, c43640.length() - 1); // extract most of it + String e43640 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d43640.getBytes()))); // B64 encode and decode it + String f43640 = e43640.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g43640 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g43640); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01503.java b/OWASP DATASET/BenchmarkTest01503.java new file mode 100644 index 0000000000000000000000000000000000000000..cda7551f6fe835bf8fbd6f79a84f566c67d53c4a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01503.java @@ -0,0 +1,142 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01503") +public class BenchmarkTest01503 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01503"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("SHA1", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01504.java b/OWASP DATASET/BenchmarkTest01504.java new file mode 100644 index 0000000000000000000000000000000000000000..009b5642097e153fb430e3cab278d492f5d3c753 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01504.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01504") +public class BenchmarkTest01504 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01504"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01505.java b/OWASP DATASET/BenchmarkTest01505.java new file mode 100644 index 0000000000000000000000000000000000000000..88ede36e03d3214e16f76169421d57767459535d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01505.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01505") +public class BenchmarkTest01505 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01505"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + java.io.PrintWriter out = response.getWriter(); + out.write("\n\n\n

"); + out.format(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + out.write("\n

\n\n"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01506.java b/OWASP DATASET/BenchmarkTest01506.java new file mode 100644 index 0000000000000000000000000000000000000000..c90a1944fbc9758dcc92ad988e0f89a64e66e7c5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01506.java @@ -0,0 +1,67 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01506") +public class BenchmarkTest01506 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01506"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(bar, obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01507.java b/OWASP DATASET/BenchmarkTest01507.java new file mode 100644 index 0000000000000000000000000000000000000000..bd699c3f392b17e9153debbfed9a01070cb2227a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01507.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01507") +public class BenchmarkTest01507 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01507"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(bar, obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01508.java b/OWASP DATASET/BenchmarkTest01508.java new file mode 100644 index 0000000000000000000000000000000000000000..04c21ddee3e6ffe676b371106ea1344abfe52653 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01508.java @@ -0,0 +1,69 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-02/BenchmarkTest01508") +public class BenchmarkTest01508 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01508"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar.toCharArray()); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01509.java b/OWASP DATASET/BenchmarkTest01509.java new file mode 100644 index 0000000000000000000000000000000000000000..f0810134d405be8cf7345cb6ea848481946c2ac3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01509.java @@ -0,0 +1,65 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01509") +public class BenchmarkTest01509 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01509"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01510.java b/OWASP DATASET/BenchmarkTest01510.java new file mode 100644 index 0000000000000000000000000000000000000000..8f942efe7d0087e08fd3158d349703a59f43be39 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01510.java @@ -0,0 +1,67 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01510") +public class BenchmarkTest01510 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01510"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {bar, "b"}; + response.getWriter().printf("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01511.java b/OWASP DATASET/BenchmarkTest01511.java new file mode 100644 index 0000000000000000000000000000000000000000..40c7c434b1547b228c0116b8ddb8c199e413855d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01511.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01511") +public class BenchmarkTest01511 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01511"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {bar, "b"}; + response.getWriter().printf("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01512.java b/OWASP DATASET/BenchmarkTest01512.java new file mode 100644 index 0000000000000000000000000000000000000000..34cde777ca890ab6d0b800ecc08a6dd730470579 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01512.java @@ -0,0 +1,72 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01512") +public class BenchmarkTest01512 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01512"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(bar, obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz76583 = new StringBuilder(param); + bar = + sbxyz76583 + .replace(param.length() - "Z".length(), param.length(), "Z") + .toString(); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01513.java b/OWASP DATASET/BenchmarkTest01513.java new file mode 100644 index 0000000000000000000000000000000000000000..445e1d813e47052e751326b2cec09c829fecf681 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01513.java @@ -0,0 +1,69 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01513") +public class BenchmarkTest01513 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01513"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar.toCharArray()); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01514.java b/OWASP DATASET/BenchmarkTest01514.java new file mode 100644 index 0000000000000000000000000000000000000000..88df38e6f4134361e496d45ee2275e5f97b3182e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01514.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01514") +public class BenchmarkTest01514 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01514"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map56316 = new java.util.HashMap(); + map56316.put("keyA-56316", "a_Value"); // put some stuff in the collection + map56316.put("keyB-56316", param); // put it in a collection + map56316.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map56316.get("keyB-56316"); // get it back out + bar = (String) map56316.get("keyA-56316"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01515.java b/OWASP DATASET/BenchmarkTest01515.java new file mode 100644 index 0000000000000000000000000000000000000000..52f436f20b504923e5346fb8fb0a1779acdef5d2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01515.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01515") +public class BenchmarkTest01515 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01515"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a84124 = param; // assign + StringBuilder b84124 = new StringBuilder(a84124); // stick in stringbuilder + b84124.append(" SafeStuff"); // append some safe content + b84124.replace( + b84124.length() - "Chars".length(), + b84124.length(), + "Chars"); // replace some of the end content + java.util.HashMap map84124 = new java.util.HashMap(); + map84124.put("key84124", b84124.toString()); // put in a collection + String c84124 = (String) map84124.get("key84124"); // get it back out + String d84124 = c84124.substring(0, c84124.length() - 1); // extract most of it + String e84124 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d84124.getBytes()))); // B64 encode and decode it + String f84124 = e84124.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g84124 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g84124); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01516.java b/OWASP DATASET/BenchmarkTest01516.java new file mode 100644 index 0000000000000000000000000000000000000000..a2e6b0378a1d5dd8063f89a67de149ee16279b24 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01516.java @@ -0,0 +1,107 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01516") +public class BenchmarkTest01516 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01516"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String a1 = ""; + String a2 = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + } else { + a1 = "sh"; + a2 = "-c"; + } + String[] args = {a1, a2, "echo " + bar}; + + ProcessBuilder pb = new ProcessBuilder(); + + pb.command(args); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a84214 = param; // assign + StringBuilder b84214 = new StringBuilder(a84214); // stick in stringbuilder + b84214.append(" SafeStuff"); // append some safe content + b84214.replace( + b84214.length() - "Chars".length(), + b84214.length(), + "Chars"); // replace some of the end content + java.util.HashMap map84214 = new java.util.HashMap(); + map84214.put("key84214", b84214.toString()); // put in a collection + String c84214 = (String) map84214.get("key84214"); // get it back out + String d84214 = c84214.substring(0, c84214.length() - 1); // extract most of it + String e84214 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d84214.getBytes()))); // B64 encode and decode it + String f84214 = e84214.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g84214 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g84214); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01517.java b/OWASP DATASET/BenchmarkTest01517.java new file mode 100644 index 0000000000000000000000000000000000000000..b124447841f29513ddc9a30ce46671187feda79e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01517.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01517") +public class BenchmarkTest01517 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01517"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String a1 = ""; + String a2 = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + } else { + a1 = "sh"; + a2 = "-c"; + } + String[] args = {a1, a2, "echo " + bar}; + + ProcessBuilder pb = new ProcessBuilder(args); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.lang.String[]) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01518.java b/OWASP DATASET/BenchmarkTest01518.java new file mode 100644 index 0000000000000000000000000000000000000000..4097b14184d24598e7d8630575cfbe7c701b6943 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01518.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01518") +public class BenchmarkTest01518 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01518"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + float rand = new java.util.Random().nextFloat(); + String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "Floyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a96602 = param; // assign + StringBuilder b96602 = new StringBuilder(a96602); // stick in stringbuilder + b96602.append(" SafeStuff"); // append some safe content + b96602.replace( + b96602.length() - "Chars".length(), + b96602.length(), + "Chars"); // replace some of the end content + java.util.HashMap map96602 = new java.util.HashMap(); + map96602.put("key96602", b96602.toString()); // put in a collection + String c96602 = (String) map96602.get("key96602"); // get it back out + String d96602 = c96602.substring(0, c96602.length() - 1); // extract most of it + String e96602 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d96602.getBytes()))); // B64 encode and decode it + String f96602 = e96602.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f96602); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01519.java b/OWASP DATASET/BenchmarkTest01519.java new file mode 100644 index 0000000000000000000000000000000000000000..fe256911cae0ce46d7ed1a1ceeeb6f1444bfef0a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01519.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01519") +public class BenchmarkTest01519 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01519"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + float rand = new java.util.Random().nextFloat(); + String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "Floyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz3774 = new StringBuilder(param); + bar = + sbxyz3774 + .replace(param.length() - "Z".length(), param.length(), "Z") + .toString(); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01520.java b/OWASP DATASET/BenchmarkTest01520.java new file mode 100644 index 0000000000000000000000000000000000000000..57b6ba72570d384433656d099eb12a347a21d63a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01520.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01520") +public class BenchmarkTest01520 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01520"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map44642 = new java.util.HashMap(); + map44642.put("keyA-44642", "a_Value"); // put some stuff in the collection + map44642.put("keyB-44642", param); // put it in a collection + map44642.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map44642.get("keyB-44642"); // get it back out + bar = (String) map44642.get("keyA-44642"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01521.java b/OWASP DATASET/BenchmarkTest01521.java new file mode 100644 index 0000000000000000000000000000000000000000..a1cf8dffb7ed9c908f2529d52838ab45023be060 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01521.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest01521") +public class BenchmarkTest01521 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01521"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01522.java b/OWASP DATASET/BenchmarkTest01522.java new file mode 100644 index 0000000000000000000000000000000000000000..5a51cb0968c41f7f1030bc0f3dfd830a6f629d29 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01522.java @@ -0,0 +1,90 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest01522") +public class BenchmarkTest01522 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01522"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01523.java b/OWASP DATASET/BenchmarkTest01523.java new file mode 100644 index 0000000000000000000000000000000000000000..7fadf45801c74c04f3fbadf39693a1415f82f858 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01523.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest01523") +public class BenchmarkTest01523 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01523"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a94015 = param; // assign + StringBuilder b94015 = new StringBuilder(a94015); // stick in stringbuilder + b94015.append(" SafeStuff"); // append some safe content + b94015.replace( + b94015.length() - "Chars".length(), + b94015.length(), + "Chars"); // replace some of the end content + java.util.HashMap map94015 = new java.util.HashMap(); + map94015.put("key94015", b94015.toString()); // put in a collection + String c94015 = (String) map94015.get("key94015"); // get it back out + String d94015 = c94015.substring(0, c94015.length() - 1); // extract most of it + String e94015 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d94015.getBytes()))); // B64 encode and decode it + String f94015 = e94015.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f94015); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01524.java b/OWASP DATASET/BenchmarkTest01524.java new file mode 100644 index 0000000000000000000000000000000000000000..8585561b4e152118667ca1a082f1081386830976 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01524.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest01524") +public class BenchmarkTest01524 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01524"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01525.java b/OWASP DATASET/BenchmarkTest01525.java new file mode 100644 index 0000000000000000000000000000000000000000..16536752f1fac8b735fce53c11303c87caf7328e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01525.java @@ -0,0 +1,71 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01525") +public class BenchmarkTest01525 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01525"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write("Parameter value: " + bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz67457 = new StringBuilder(param); + bar = + sbxyz67457 + .replace(param.length() - "Z".length(), param.length(), "Z") + .toString(); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01526.java b/OWASP DATASET/BenchmarkTest01526.java new file mode 100644 index 0000000000000000000000000000000000000000..2729d36f23d96fe4085155d5019e3072313cb222 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01526.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01526") +public class BenchmarkTest01526 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01526"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01527.java b/OWASP DATASET/BenchmarkTest01527.java new file mode 100644 index 0000000000000000000000000000000000000000..eb61f30fe9fc60f4f9bcf3321baa8235c7ce3e02 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01527.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01527") +public class BenchmarkTest01527 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01527"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01528.java b/OWASP DATASET/BenchmarkTest01528.java new file mode 100644 index 0000000000000000000000000000000000000000..cd75f47edea3e0041686af96135e73554d008070 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01528.java @@ -0,0 +1,98 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01528") +public class BenchmarkTest01528 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01528"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01529.java b/OWASP DATASET/BenchmarkTest01529.java new file mode 100644 index 0000000000000000000000000000000000000000..f4b233fd965e1b02063aa913a3c42e57681bc46d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01529.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01529") +public class BenchmarkTest01529 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01529"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ping -c1 "); + args = new String[] {a1, a2, cmd + bar}; + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01530.java b/OWASP DATASET/BenchmarkTest01530.java new file mode 100644 index 0000000000000000000000000000000000000000..6a8479e24a87c9e798bcdca8235c554d23dfe99f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01530.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01530") +public class BenchmarkTest01530 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01530"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01531.java b/OWASP DATASET/BenchmarkTest01531.java new file mode 100644 index 0000000000000000000000000000000000000000..5b2570c9806a6f38b6b09880b403f77952136bdd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01531.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01531") +public class BenchmarkTest01531 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01531"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01532.java b/OWASP DATASET/BenchmarkTest01532.java new file mode 100644 index 0000000000000000000000000000000000000000..d2b4b5cb43aa99ba0f904640b4c01669c1c370ad --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01532.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01532") +public class BenchmarkTest01532 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01532"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = + r.exec(cmd + bar, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01533.java b/OWASP DATASET/BenchmarkTest01533.java new file mode 100644 index 0000000000000000000000000000000000000000..a3c6becdf5484e4b09e3eb7ed59d752f9984d047 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01533.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01533") +public class BenchmarkTest01533 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01533"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + try { + Process p = r.exec(cmd, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01534.java b/OWASP DATASET/BenchmarkTest01534.java new file mode 100644 index 0000000000000000000000000000000000000000..d5d4a8ba5eb45bd1f7778b618eaed3e518b0cb5a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01534.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01534") +public class BenchmarkTest01534 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01534"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01535.java b/OWASP DATASET/BenchmarkTest01535.java new file mode 100644 index 0000000000000000000000000000000000000000..881ee42cb84ae830487a65f4b55534f17bd254ee --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01535.java @@ -0,0 +1,125 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01535") +public class BenchmarkTest01535 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01535"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01536.java b/OWASP DATASET/BenchmarkTest01536.java new file mode 100644 index 0000000000000000000000000000000000000000..24bb15931940e0f6d8d5b479c6fc362baa0fa58a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01536.java @@ -0,0 +1,139 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01536") +public class BenchmarkTest01536 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01536"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a79311 = param; // assign + StringBuilder b79311 = new StringBuilder(a79311); // stick in stringbuilder + b79311.append(" SafeStuff"); // append some safe content + b79311.replace( + b79311.length() - "Chars".length(), + b79311.length(), + "Chars"); // replace some of the end content + java.util.HashMap map79311 = new java.util.HashMap(); + map79311.put("key79311", b79311.toString()); // put in a collection + String c79311 = (String) map79311.get("key79311"); // get it back out + String d79311 = c79311.substring(0, c79311.length() - 1); // extract most of it + String e79311 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d79311.getBytes()))); // B64 encode and decode it + String f79311 = e79311.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g79311 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g79311); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01537.java b/OWASP DATASET/BenchmarkTest01537.java new file mode 100644 index 0000000000000000000000000000000000000000..6435142f33cc20038326de1124e991cbd83f08bf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01537.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01537") +public class BenchmarkTest01537 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01537"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + double rand = getNextNumber(numGen); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonatella"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + double getNextNumber(java.util.Random generator) { + return generator.nextDouble(); + } + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map7472 = new java.util.HashMap(); + map7472.put("keyA-7472", "a_Value"); // put some stuff in the collection + map7472.put("keyB-7472", param); // put it in a collection + map7472.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map7472.get("keyB-7472"); // get it back out + bar = (String) map7472.get("keyA-7472"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01538.java b/OWASP DATASET/BenchmarkTest01538.java new file mode 100644 index 0000000000000000000000000000000000000000..d48c5df526b0cb7adc7e01fbf3e05f5bf11d4728 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01538.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01538") +public class BenchmarkTest01538 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01538"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map82396 = new java.util.HashMap(); + map82396.put("keyA-82396", "a_Value"); // put some stuff in the collection + map82396.put("keyB-82396", param); // put it in a collection + map82396.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map82396.get("keyB-82396"); // get it back out + bar = (String) map82396.get("keyA-82396"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01539.java b/OWASP DATASET/BenchmarkTest01539.java new file mode 100644 index 0000000000000000000000000000000000000000..6bcaf78e3db9b50b7c4ceaf7cace27d2f6fe56f4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01539.java @@ -0,0 +1,143 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01539") +public class BenchmarkTest01539 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01539"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01540.java b/OWASP DATASET/BenchmarkTest01540.java new file mode 100644 index 0000000000000000000000000000000000000000..7b8066898ffc05bb0c320419a24d5488fc2a5468 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01540.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01540") +public class BenchmarkTest01540 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01540"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01541.java b/OWASP DATASET/BenchmarkTest01541.java new file mode 100644 index 0000000000000000000000000000000000000000..0dd4cbf8e06644db204411fd3fa64d70b46efbcc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01541.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01541") +public class BenchmarkTest01541 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01541"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01542.java b/OWASP DATASET/BenchmarkTest01542.java new file mode 100644 index 0000000000000000000000000000000000000000..140a3a73d06ce1191921357336dec866e45abc60 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01542.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01542") +public class BenchmarkTest01542 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01542"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + float rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextFloat(); + String rememberMeKey = + Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeFloyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextFloat() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextFloat() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map98601 = new java.util.HashMap(); + map98601.put("keyA-98601", "a-Value"); // put some stuff in the collection + map98601.put("keyB-98601", param); // put it in a collection + map98601.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map98601.get("keyB-98601"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01543.java b/OWASP DATASET/BenchmarkTest01543.java new file mode 100644 index 0000000000000000000000000000000000000000..8b8b786aad487d641461c2a5ce1f33e2bc9dc08b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01543.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01543") +public class BenchmarkTest01543 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01543"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + float rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextFloat(); + String rememberMeKey = + Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeFloyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextFloat() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextFloat() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01544.java b/OWASP DATASET/BenchmarkTest01544.java new file mode 100644 index 0000000000000000000000000000000000000000..1184c05e45c42b7080439c388f8a5de0e2147814 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01544.java @@ -0,0 +1,126 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01544") +public class BenchmarkTest01544 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01544"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + float rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextFloat(); + String rememberMeKey = + Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeFloyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextFloat() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextFloat() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01545.java b/OWASP DATASET/BenchmarkTest01545.java new file mode 100644 index 0000000000000000000000000000000000000000..a7dc79b6c630f5099ea3d1ef88e5c051e10a04c3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01545.java @@ -0,0 +1,137 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01545") +public class BenchmarkTest01545 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01545"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + double stuff = java.security.SecureRandom.getInstance("SHA1PRNG").nextGaussian(); + String rememberMeKey = + Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "SafeGayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextGaussian() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextGaussian() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a43050 = param; // assign + StringBuilder b43050 = new StringBuilder(a43050); // stick in stringbuilder + b43050.append(" SafeStuff"); // append some safe content + b43050.replace( + b43050.length() - "Chars".length(), + b43050.length(), + "Chars"); // replace some of the end content + java.util.HashMap map43050 = new java.util.HashMap(); + map43050.put("key43050", b43050.toString()); // put in a collection + String c43050 = (String) map43050.get("key43050"); // get it back out + String d43050 = c43050.substring(0, c43050.length() - 1); // extract most of it + String e43050 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d43050.getBytes()))); // B64 encode and decode it + String f43050 = e43050.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g43050 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g43050); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01546.java b/OWASP DATASET/BenchmarkTest01546.java new file mode 100644 index 0000000000000000000000000000000000000000..1b8243836c61556fdbf94dd7f215bba3c37865cc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01546.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01546") +public class BenchmarkTest01546 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01546"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String^,java.lang.Object) + request.getSession().putValue(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: 10340 saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01547.java b/OWASP DATASET/BenchmarkTest01547.java new file mode 100644 index 0000000000000000000000000000000000000000..0f65c868d2cfba15cdfc00d9cbb0d6fc9bf1908d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01547.java @@ -0,0 +1,71 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01547") +public class BenchmarkTest01547 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01547"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01548.java b/OWASP DATASET/BenchmarkTest01548.java new file mode 100644 index 0000000000000000000000000000000000000000..769cf550a687ced421b51c27d386bffc2681cc19 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01548.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01548") +public class BenchmarkTest01548 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01548"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01549.java b/OWASP DATASET/BenchmarkTest01549.java new file mode 100644 index 0000000000000000000000000000000000000000..9b2d37ede25f2ef5b471b94cafc7c6d7d80791a5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01549.java @@ -0,0 +1,80 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01549") +public class BenchmarkTest01549 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01549"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01550.java b/OWASP DATASET/BenchmarkTest01550.java new file mode 100644 index 0000000000000000000000000000000000000000..fe16a35b43c954c3017a13e71865058284d0be1f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01550.java @@ -0,0 +1,90 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01550") +public class BenchmarkTest01550 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01550"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a86153 = param; // assign + StringBuilder b86153 = new StringBuilder(a86153); // stick in stringbuilder + b86153.append(" SafeStuff"); // append some safe content + b86153.replace( + b86153.length() - "Chars".length(), + b86153.length(), + "Chars"); // replace some of the end content + java.util.HashMap map86153 = new java.util.HashMap(); + map86153.put("key86153", b86153.toString()); // put in a collection + String c86153 = (String) map86153.get("key86153"); // get it back out + String d86153 = c86153.substring(0, c86153.length() - 1); // extract most of it + String e86153 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d86153.getBytes()))); // B64 encode and decode it + String f86153 = e86153.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f86153); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01551.java b/OWASP DATASET/BenchmarkTest01551.java new file mode 100644 index 0000000000000000000000000000000000000000..8506efe4793b1b1750aa87cf44f9c93f8431b36f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01551.java @@ -0,0 +1,71 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01551") +public class BenchmarkTest01551 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01551"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz68516 = new StringBuilder(param); + String bar = sbxyz68516.append("_SafeStuff").toString(); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01552.java b/OWASP DATASET/BenchmarkTest01552.java new file mode 100644 index 0000000000000000000000000000000000000000..30ccfb20b54ce67bad7d9586fc2d52ad40938044 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01552.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01552") +public class BenchmarkTest01552 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01552"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01553.java b/OWASP DATASET/BenchmarkTest01553.java new file mode 100644 index 0000000000000000000000000000000000000000..6299667bc806eaac3236b66a74edf21b4753d8b6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01553.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01553") +public class BenchmarkTest01553 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01553"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.execute(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring execute method doesn't return results."); + + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map99501 = new java.util.HashMap(); + map99501.put("keyA-99501", "a_Value"); // put some stuff in the collection + map99501.put("keyB-99501", param); // put it in a collection + map99501.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map99501.get("keyB-99501"); // get it back out + bar = (String) map99501.get("keyA-99501"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01554.java b/OWASP DATASET/BenchmarkTest01554.java new file mode 100644 index 0000000000000000000000000000000000000000..98f41ac9b11edf27aa57ab57bb0ada5eac2e6614 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01554.java @@ -0,0 +1,98 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01554") +public class BenchmarkTest01554 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01554"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List> list = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForList(sql); + response.getWriter().println("Your results are:
"); + + // System.out.println("Your results are"); + + for (Object o : list) { + response.getWriter() + .println( + org.owasp.esapi.ESAPI.encoder().encodeForHTML(o.toString()) + + "
"); + // System.out.println(o.toString()); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01555.java b/OWASP DATASET/BenchmarkTest01555.java new file mode 100644 index 0000000000000000000000000000000000000000..0c43ca1843dd58111e8888212e01ea425bae4957 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01555.java @@ -0,0 +1,90 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01555") +public class BenchmarkTest01555 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01555"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // Long results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForLong(sql); + Long results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Long.class); + response.getWriter().println("Your results are: " + String.valueOf(results)); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01556.java b/OWASP DATASET/BenchmarkTest01556.java new file mode 100644 index 0000000000000000000000000000000000000000..ca2835dc1d45c08efc45501dbdb806e809dbd396 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01556.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01556") +public class BenchmarkTest01556 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01556"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // Long results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForLong(sql); + Long results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Long.class); + response.getWriter().println("Your results are: " + String.valueOf(results)); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01557.java b/OWASP DATASET/BenchmarkTest01557.java new file mode 100644 index 0000000000000000000000000000000000000000..3143d858e083792168227b8762cce0e0601d5677 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01557.java @@ -0,0 +1,80 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01557") +public class BenchmarkTest01557 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01557"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map20581 = new java.util.HashMap(); + map20581.put("keyA-20581", "a-Value"); // put some stuff in the collection + map20581.put("keyB-20581", param); // put it in a collection + map20581.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map20581.get("keyB-20581"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01558.java b/OWASP DATASET/BenchmarkTest01558.java new file mode 100644 index 0000000000000000000000000000000000000000..eb4cf5867dbfe25ccee6dc272fd66f4a3e2e3bda --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01558.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01558") +public class BenchmarkTest01558 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01558"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01559.java b/OWASP DATASET/BenchmarkTest01559.java new file mode 100644 index 0000000000000000000000000000000000000000..d0ca5455325d597bc34b1d9156809dd847876681 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01559.java @@ -0,0 +1,80 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01559") +public class BenchmarkTest01559 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01559"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map31651 = new java.util.HashMap(); + map31651.put("keyA-31651", "a-Value"); // put some stuff in the collection + map31651.put("keyB-31651", param); // put it in a collection + map31651.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map31651.get("keyB-31651"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01560.java b/OWASP DATASET/BenchmarkTest01560.java new file mode 100644 index 0000000000000000000000000000000000000000..48217e41fd953b8adfc69a9ad9b1b002b07fb31a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01560.java @@ -0,0 +1,80 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01560") +public class BenchmarkTest01560 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01560"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01561.java b/OWASP DATASET/BenchmarkTest01561.java new file mode 100644 index 0000000000000000000000000000000000000000..664ab9d7c5c7e1476a63cfcabfba932dee730f4f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01561.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest01561") +public class BenchmarkTest01561 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01561"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + org.w3c.dom.NodeList nodeList = + (org.w3c.dom.NodeList) + xp.compile(expression) + .evaluate(xmlDocument, javax.xml.xpath.XPathConstants.NODESET); + + response.getWriter().println("Your query results are:
"); + + for (int i = 0; i < nodeList.getLength(); i++) { + org.w3c.dom.Element value = (org.w3c.dom.Element) nodeList.item(i); + response.getWriter().println(value.getTextContent() + "
"); + } + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01562.java b/OWASP DATASET/BenchmarkTest01562.java new file mode 100644 index 0000000000000000000000000000000000000000..d9ba071a673f7bb9e16f45b72151eed8048abf75 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01562.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest01562") +public class BenchmarkTest01562 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest01562"); + if (param == null) param = ""; + + String bar = new Test().doSomething(request, param); + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + org.w3c.dom.NodeList nodeList = + (org.w3c.dom.NodeList) + xp.compile(expression) + .evaluate(xmlDocument, javax.xml.xpath.XPathConstants.NODESET); + + response.getWriter().println("Your query results are:
"); + + for (int i = 0; i < nodeList.getLength(); i++) { + org.w3c.dom.Element value = (org.w3c.dom.Element) nodeList.item(i); + response.getWriter().println(value.getTextContent() + "
"); + } + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01563.java b/OWASP DATASET/BenchmarkTest01563.java new file mode 100644 index 0000000000000000000000000000000000000000..dbed079f1e024dba58cf39d43b762ba1e4d2bb40 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01563.java @@ -0,0 +1,164 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01563") +public class BenchmarkTest01563 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01563"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01564.java b/OWASP DATASET/BenchmarkTest01564.java new file mode 100644 index 0000000000000000000000000000000000000000..e0e9b38e43b7fe04668153ed69c51fd5fb6e296f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01564.java @@ -0,0 +1,162 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01564") +public class BenchmarkTest01564 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01564"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01565.java b/OWASP DATASET/BenchmarkTest01565.java new file mode 100644 index 0000000000000000000000000000000000000000..14111bee44de0281cb9f29ef4035d21a4d84359b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01565.java @@ -0,0 +1,131 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01565") +public class BenchmarkTest01565 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01565"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01566.java b/OWASP DATASET/BenchmarkTest01566.java new file mode 100644 index 0000000000000000000000000000000000000000..ca97e13fe2f0028902fbb14df1a8fc725c657ab8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01566.java @@ -0,0 +1,132 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01566") +public class BenchmarkTest01566 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01566"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01567.java b/OWASP DATASET/BenchmarkTest01567.java new file mode 100644 index 0000000000000000000000000000000000000000..4d7f35561676fc62375ae570d59c3052894d7cb6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01567.java @@ -0,0 +1,153 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-01/BenchmarkTest01567") +public class BenchmarkTest01567 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01567"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + // java.security.SecureRandom random = new java.security.SecureRandom(); + // byte[] iv = random.generateSeed(16); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg2", "AES/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a29366 = param; // assign + StringBuilder b29366 = new StringBuilder(a29366); // stick in stringbuilder + b29366.append(" SafeStuff"); // append some safe content + b29366.replace( + b29366.length() - "Chars".length(), + b29366.length(), + "Chars"); // replace some of the end content + java.util.HashMap map29366 = new java.util.HashMap(); + map29366.put("key29366", b29366.toString()); // put in a collection + String c29366 = (String) map29366.get("key29366"); // get it back out + String d29366 = c29366.substring(0, c29366.length() - 1); // extract most of it + String e29366 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d29366.getBytes()))); // B64 encode and decode it + String f29366 = e29366.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g29366 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g29366); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01568.java b/OWASP DATASET/BenchmarkTest01568.java new file mode 100644 index 0000000000000000000000000000000000000000..c9d7b9b9a0c63aa1a5f5af88d9e5372414e43127 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01568.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest01568") +public class BenchmarkTest01568 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01568"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + javax.naming.directory.DirContext ctx = ads.getDirContext(); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person)(uid=" + bar + "))"; + // System.out.println("Filter " + filter); + boolean found = false; + javax.naming.NamingEnumeration results = + ctx.search(base, filter, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01569.java b/OWASP DATASET/BenchmarkTest01569.java new file mode 100644 index 0000000000000000000000000000000000000000..40c20e8ad2b8334552754fe668e57991794ba285 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01569.java @@ -0,0 +1,131 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest01569") +public class BenchmarkTest01569 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01569"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + javax.naming.directory.DirContext ctx = ads.getDirContext(); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person)(uid=" + bar + "))"; + // System.out.println("Filter " + filter); + boolean found = false; + javax.naming.NamingEnumeration results = + ctx.search(base, filter, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a75250 = param; // assign + StringBuilder b75250 = new StringBuilder(a75250); // stick in stringbuilder + b75250.append(" SafeStuff"); // append some safe content + b75250.replace( + b75250.length() - "Chars".length(), + b75250.length(), + "Chars"); // replace some of the end content + java.util.HashMap map75250 = new java.util.HashMap(); + map75250.put("key75250", b75250.toString()); // put in a collection + String c75250 = (String) map75250.get("key75250"); // get it back out + String d75250 = c75250.substring(0, c75250.length() - 1); // extract most of it + String e75250 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d75250.getBytes()))); // B64 encode and decode it + String f75250 = e75250.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g75250 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g75250); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01570.java b/OWASP DATASET/BenchmarkTest01570.java new file mode 100644 index 0000000000000000000000000000000000000000..9ec7d6b474a8abb641a4db2138237cc6e1258312 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01570.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01570") +public class BenchmarkTest01570 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01570"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01571.java b/OWASP DATASET/BenchmarkTest01571.java new file mode 100644 index 0000000000000000000000000000000000000000..19091f2c6c806af4e157b1e9ecf79819e8a75b12 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01571.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01571") +public class BenchmarkTest01571 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01571"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + java.io.File fileTarget = new java.io.File(bar, "/Test.txt"); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01572.java b/OWASP DATASET/BenchmarkTest01572.java new file mode 100644 index 0000000000000000000000000000000000000000..79f8f50c9b258aa4834a1698a3041bd01284e326 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01572.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01572") +public class BenchmarkTest01572 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01572"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(new java.io.File(fileName)); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting FileInputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01573.java b/OWASP DATASET/BenchmarkTest01573.java new file mode 100644 index 0000000000000000000000000000000000000000..498b2c1fae7ca637786598085fb01a223d36e672 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01573.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01573") +public class BenchmarkTest01573 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01573"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(new java.io.File(fileName)); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting FileInputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01574.java b/OWASP DATASET/BenchmarkTest01574.java new file mode 100644 index 0000000000000000000000000000000000000000..251ef4e2c9580688d2fb6a87bb68ccdf59c9052d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01574.java @@ -0,0 +1,93 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01574") +public class BenchmarkTest01574 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01574"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName, false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map48244 = new java.util.HashMap(); + map48244.put("keyA-48244", "a_Value"); // put some stuff in the collection + map48244.put("keyB-48244", param); // put it in a collection + map48244.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map48244.get("keyB-48244"); // get it back out + bar = (String) map48244.get("keyA-48244"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01575.java b/OWASP DATASET/BenchmarkTest01575.java new file mode 100644 index 0000000000000000000000000000000000000000..5804e928c8c04fa210b842ca569b22bdfaeca04c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01575.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01575") +public class BenchmarkTest01575 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01575"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + double value = java.lang.Math.random(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Doug"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + response.getWriter().println("Weak Randomness Test java.lang.Math.random() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01576.java b/OWASP DATASET/BenchmarkTest01576.java new file mode 100644 index 0000000000000000000000000000000000000000..4030f46a30cf5e281c076084e7b73bc5095e536a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01576.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01576") +public class BenchmarkTest01576 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01576"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = + java.security.MessageDigest.getInstance("SHA-512", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01577.java b/OWASP DATASET/BenchmarkTest01577.java new file mode 100644 index 0000000000000000000000000000000000000000..7389cf35a45aa11dc48a4880e68f0b115fad1bcf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01577.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01577") +public class BenchmarkTest01577 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01577"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01578.java b/OWASP DATASET/BenchmarkTest01578.java new file mode 100644 index 0000000000000000000000000000000000000000..1e9253b514a9869bfbdc546c0c26a5a88c4cf8d7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01578.java @@ -0,0 +1,111 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01578") +public class BenchmarkTest01578 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01578"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-256"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz85952 = new StringBuilder(param); + String bar = sbxyz85952.append("_SafeStuff").toString(); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01579.java b/OWASP DATASET/BenchmarkTest01579.java new file mode 100644 index 0000000000000000000000000000000000000000..33587507ac1cfe738298f68c2074244e57a52e61 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01579.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01579") +public class BenchmarkTest01579 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01579"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01580.java b/OWASP DATASET/BenchmarkTest01580.java new file mode 100644 index 0000000000000000000000000000000000000000..c8d26125dfd7deceaace7521a811ce24799edb57 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01580.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01580") +public class BenchmarkTest01580 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01580"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01581.java b/OWASP DATASET/BenchmarkTest01581.java new file mode 100644 index 0000000000000000000000000000000000000000..cc1de5a27cafc1b3accbb7af22c49796f68c75d6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01581.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01581") +public class BenchmarkTest01581 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01581"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01582.java b/OWASP DATASET/BenchmarkTest01582.java new file mode 100644 index 0000000000000000000000000000000000000000..32b2cc26ee0842328fc8b2f565d150a80d30166c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01582.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01582") +public class BenchmarkTest01582 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01582"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map17367 = new java.util.HashMap(); + map17367.put("keyA-17367", "a_Value"); // put some stuff in the collection + map17367.put("keyB-17367", param); // put it in a collection + map17367.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map17367.get("keyB-17367"); // get it back out + bar = (String) map17367.get("keyA-17367"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01583.java b/OWASP DATASET/BenchmarkTest01583.java new file mode 100644 index 0000000000000000000000000000000000000000..a0fe85e01c22dba6b3486c9d84a475f0448cfd5a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01583.java @@ -0,0 +1,69 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01583") +public class BenchmarkTest01583 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01583"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + java.io.PrintWriter out = response.getWriter(); + out.write("\n\n\n

"); + out.format(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + out.write("\n

\n\n"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz82559 = new StringBuilder(param); + String bar = sbxyz82559.append("_SafeStuff").toString(); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01584.java b/OWASP DATASET/BenchmarkTest01584.java new file mode 100644 index 0000000000000000000000000000000000000000..1941206e213c527cef583aca5f435dcc1b27bec7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01584.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01584") +public class BenchmarkTest01584 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01584"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(java.util.Locale.US, bar, obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01585.java b/OWASP DATASET/BenchmarkTest01585.java new file mode 100644 index 0000000000000000000000000000000000000000..8e3a9a3dab58751e5ee058d2b4dc6ceaf7cc63a1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01585.java @@ -0,0 +1,65 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01585") +public class BenchmarkTest01585 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01585"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(bar, obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01586.java b/OWASP DATASET/BenchmarkTest01586.java new file mode 100644 index 0000000000000000000000000000000000000000..386c7e5d0cd835230d3401e74c50785eb202c7c7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01586.java @@ -0,0 +1,64 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01586") +public class BenchmarkTest01586 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01586"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01587.java b/OWASP DATASET/BenchmarkTest01587.java new file mode 100644 index 0000000000000000000000000000000000000000..50beeef8ce5c345d503b42d77d3e98ddfdd0a992 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01587.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01587") +public class BenchmarkTest01587 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01587"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(java.util.Locale.US, bar, obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01588.java b/OWASP DATASET/BenchmarkTest01588.java new file mode 100644 index 0000000000000000000000000000000000000000..42091d4f2002c9c63b917d5e10f20c4240c2b74e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01588.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01588") +public class BenchmarkTest01588 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01588"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(java.util.Locale.US, bar, obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01589.java b/OWASP DATASET/BenchmarkTest01589.java new file mode 100644 index 0000000000000000000000000000000000000000..07771df8a46427d2b78984fdf5c80ba76e36981c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01589.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01589") +public class BenchmarkTest01589 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01589"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {bar, "b"}; + response.getWriter().printf("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01590.java b/OWASP DATASET/BenchmarkTest01590.java new file mode 100644 index 0000000000000000000000000000000000000000..406223b79f669a12c58f981148fb442a28cdc88e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01590.java @@ -0,0 +1,65 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01590") +public class BenchmarkTest01590 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01590"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(bar, obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01591.java b/OWASP DATASET/BenchmarkTest01591.java new file mode 100644 index 0000000000000000000000000000000000000000..46af59ae587597510416f091a45c029c02006820 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01591.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01591") +public class BenchmarkTest01591 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01591"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(bar, obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a1207 = param; // assign + StringBuilder b1207 = new StringBuilder(a1207); // stick in stringbuilder + b1207.append(" SafeStuff"); // append some safe content + b1207.replace( + b1207.length() - "Chars".length(), + b1207.length(), + "Chars"); // replace some of the end content + java.util.HashMap map1207 = new java.util.HashMap(); + map1207.put("key1207", b1207.toString()); // put in a collection + String c1207 = (String) map1207.get("key1207"); // get it back out + String d1207 = c1207.substring(0, c1207.length() - 1); // extract most of it + String e1207 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d1207.getBytes()))); // B64 encode and decode it + String f1207 = e1207.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g1207 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g1207); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01592.java b/OWASP DATASET/BenchmarkTest01592.java new file mode 100644 index 0000000000000000000000000000000000000000..136cd1ba69545d32017a59fb7f5034eb959b1d7f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01592.java @@ -0,0 +1,69 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01592") +public class BenchmarkTest01592 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01592"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01593.java b/OWASP DATASET/BenchmarkTest01593.java new file mode 100644 index 0000000000000000000000000000000000000000..abd49d3f62af7c1da51c965a6c5206eea8ede526 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01593.java @@ -0,0 +1,69 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01593") +public class BenchmarkTest01593 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01593"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01594.java b/OWASP DATASET/BenchmarkTest01594.java new file mode 100644 index 0000000000000000000000000000000000000000..586336579a11121bce16b48f9627e2ead315f438 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01594.java @@ -0,0 +1,65 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01594") +public class BenchmarkTest01594 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01594"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz51154 = new StringBuilder(param); + String bar = sbxyz51154.append("_SafeStuff").toString(); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01595.java b/OWASP DATASET/BenchmarkTest01595.java new file mode 100644 index 0000000000000000000000000000000000000000..4283e7fb90a06af3ed334d9406975e9a5ea6352d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01595.java @@ -0,0 +1,64 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01595") +public class BenchmarkTest01595 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01595"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar.toCharArray()); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01596.java b/OWASP DATASET/BenchmarkTest01596.java new file mode 100644 index 0000000000000000000000000000000000000000..736c0f20b98aba439fb7bf6b65ec23dc87a2a730 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01596.java @@ -0,0 +1,69 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01596") +public class BenchmarkTest01596 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01596"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar.toCharArray(), 0, length); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01597.java b/OWASP DATASET/BenchmarkTest01597.java new file mode 100644 index 0000000000000000000000000000000000000000..79d61a81f4b116132070c3451956e0cf1415bf0f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01597.java @@ -0,0 +1,69 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01597") +public class BenchmarkTest01597 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01597"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar.toCharArray(), 0, length); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz81751 = new StringBuilder(param); + String bar = sbxyz81751.append("_SafeStuff").toString(); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01598.java b/OWASP DATASET/BenchmarkTest01598.java new file mode 100644 index 0000000000000000000000000000000000000000..c88251bf9efaff6e3a9724ebf598895b33490ed2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01598.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01598") +public class BenchmarkTest01598 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01598"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a75770 = param; // assign + StringBuilder b75770 = new StringBuilder(a75770); // stick in stringbuilder + b75770.append(" SafeStuff"); // append some safe content + b75770.replace( + b75770.length() - "Chars".length(), + b75770.length(), + "Chars"); // replace some of the end content + java.util.HashMap map75770 = new java.util.HashMap(); + map75770.put("key75770", b75770.toString()); // put in a collection + String c75770 = (String) map75770.get("key75770"); // get it back out + String d75770 = c75770.substring(0, c75770.length() - 1); // extract most of it + String e75770 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d75770.getBytes()))); // B64 encode and decode it + String f75770 = e75770.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f75770); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01599.java b/OWASP DATASET/BenchmarkTest01599.java new file mode 100644 index 0000000000000000000000000000000000000000..0f2714b17314f6dcb4deb76165c659b84d7fa920 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01599.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01599") +public class BenchmarkTest01599 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01599"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map20521 = new java.util.HashMap(); + map20521.put("keyA-20521", "a_Value"); // put some stuff in the collection + map20521.put("keyB-20521", param); // put it in a collection + map20521.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map20521.get("keyB-20521"); // get it back out + bar = (String) map20521.get("keyA-20521"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01600.java b/OWASP DATASET/BenchmarkTest01600.java new file mode 100644 index 0000000000000000000000000000000000000000..53413c78d68c9c6e3c8afc7bf2f32992152639f3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01600.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01600") +public class BenchmarkTest01600 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01600"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(); + + pb.command(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01601.java b/OWASP DATASET/BenchmarkTest01601.java new file mode 100644 index 0000000000000000000000000000000000000000..fadb647a75e0c7e2281765d63c0113ee8bac0e29 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01601.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01601") +public class BenchmarkTest01601 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01601"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01602.java b/OWASP DATASET/BenchmarkTest01602.java new file mode 100644 index 0000000000000000000000000000000000000000..8d663799eda3aae17c5fb1a38a37aa3bf37354dd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01602.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01602") +public class BenchmarkTest01602 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01602"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + float rand = new java.util.Random().nextFloat(); + String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "Floyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01603.java b/OWASP DATASET/BenchmarkTest01603.java new file mode 100644 index 0000000000000000000000000000000000000000..bff532c8a9bee997f85448fc74cde6e9ddeb6c3a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01603.java @@ -0,0 +1,131 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01603") +public class BenchmarkTest01603 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01603"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a74856 = param; // assign + StringBuilder b74856 = new StringBuilder(a74856); // stick in stringbuilder + b74856.append(" SafeStuff"); // append some safe content + b74856.replace( + b74856.length() - "Chars".length(), + b74856.length(), + "Chars"); // replace some of the end content + java.util.HashMap map74856 = new java.util.HashMap(); + map74856.put("key74856", b74856.toString()); // put in a collection + String c74856 = (String) map74856.get("key74856"); // get it back out + String d74856 = c74856.substring(0, c74856.length() - 1); // extract most of it + String e74856 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d74856.getBytes()))); // B64 encode and decode it + String f74856 = e74856.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g74856 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g74856); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01604.java b/OWASP DATASET/BenchmarkTest01604.java new file mode 100644 index 0000000000000000000000000000000000000000..632207870fe4ae4e98f2e2cc8e610d398903ffd9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01604.java @@ -0,0 +1,90 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest01604") +public class BenchmarkTest01604 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01604"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01605.java b/OWASP DATASET/BenchmarkTest01605.java new file mode 100644 index 0000000000000000000000000000000000000000..6ca8fc526a3f101d77f3dd0dd3350bab6f0d1e72 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01605.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest01605") +public class BenchmarkTest01605 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01605"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map97880 = new java.util.HashMap(); + map97880.put("keyA-97880", "a_Value"); // put some stuff in the collection + map97880.put("keyB-97880", param); // put it in a collection + map97880.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map97880.get("keyB-97880"); // get it back out + bar = (String) map97880.get("keyA-97880"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01606.java b/OWASP DATASET/BenchmarkTest01606.java new file mode 100644 index 0000000000000000000000000000000000000000..3b89e42a214d66ce8ed0a76a34acd10feb22b4bd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01606.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01606") +public class BenchmarkTest01606 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01606"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01607.java b/OWASP DATASET/BenchmarkTest01607.java new file mode 100644 index 0000000000000000000000000000000000000000..0c2cf7dc8b746751016e09d8c523a7aaa487af01 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01607.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01607") +public class BenchmarkTest01607 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01607"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ping -c1 "); + args = new String[] {a1, a2, cmd + bar}; + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01608.java b/OWASP DATASET/BenchmarkTest01608.java new file mode 100644 index 0000000000000000000000000000000000000000..3b93bc4ae594e5ca41178b5c74b9793064f094f7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01608.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01608") +public class BenchmarkTest01608 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01608"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map55872 = new java.util.HashMap(); + map55872.put("keyA-55872", "a_Value"); // put some stuff in the collection + map55872.put("keyB-55872", param); // put it in a collection + map55872.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map55872.get("keyB-55872"); // get it back out + bar = (String) map55872.get("keyA-55872"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01609.java b/OWASP DATASET/BenchmarkTest01609.java new file mode 100644 index 0000000000000000000000000000000000000000..8fe6ff86ea2f8f4ea8b117b7b6238bc76f8df504 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01609.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01609") +public class BenchmarkTest01609 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01609"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = + r.exec(cmd + bar, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01610.java b/OWASP DATASET/BenchmarkTest01610.java new file mode 100644 index 0000000000000000000000000000000000000000..6178cb93a1f4fd3c08be0d8fdbcfdea635e38977 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01610.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01610") +public class BenchmarkTest01610 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01610"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = + r.exec(cmd + bar, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01611.java b/OWASP DATASET/BenchmarkTest01611.java new file mode 100644 index 0000000000000000000000000000000000000000..7aa5459a7977cf72edc75b128a8d89266a372f2c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01611.java @@ -0,0 +1,127 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01611") +public class BenchmarkTest01611 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01611"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01612.java b/OWASP DATASET/BenchmarkTest01612.java new file mode 100644 index 0000000000000000000000000000000000000000..9f0bdb72652f858a58164814a87030d90de0bf09 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01612.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01612") +public class BenchmarkTest01612 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01612"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + try { + double stuff = java.security.SecureRandom.getInstance("SHA1PRNG").nextGaussian(); + String rememberMeKey = + Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "SafeGayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextGaussian() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextGaussian() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01613.java b/OWASP DATASET/BenchmarkTest01613.java new file mode 100644 index 0000000000000000000000000000000000000000..4b401f3f9798b6bcd2329eb2d9df72dba072f632 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01613.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01613") +public class BenchmarkTest01613 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01613"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + try { + int r = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "SafeIngrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01614.java b/OWASP DATASET/BenchmarkTest01614.java new file mode 100644 index 0000000000000000000000000000000000000000..f35a34bed8d595fdb299304b32a5783773d94b91 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01614.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01614") +public class BenchmarkTest01614 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01614"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + try { + long l = java.security.SecureRandom.getInstance("SHA1PRNG").nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "SafeLogan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextLong() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextLong() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01615.java b/OWASP DATASET/BenchmarkTest01615.java new file mode 100644 index 0000000000000000000000000000000000000000..3d2aae6925b97e26407ffcff05b7fa0ff6867973 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01615.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01615") +public class BenchmarkTest01615 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01615"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String^,java.lang.Object) + request.getSession().putValue(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: 10340 saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz57216 = new StringBuilder(param); + bar = + sbxyz57216 + .replace(param.length() - "Z".length(), param.length(), "Z") + .toString(); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01616.java b/OWASP DATASET/BenchmarkTest01616.java new file mode 100644 index 0000000000000000000000000000000000000000..3f6aa528038817df8dd7f3a0be7d5b3c5e9082b9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01616.java @@ -0,0 +1,90 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01616") +public class BenchmarkTest01616 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01616"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a53857 = param; // assign + StringBuilder b53857 = new StringBuilder(a53857); // stick in stringbuilder + b53857.append(" SafeStuff"); // append some safe content + b53857.replace( + b53857.length() - "Chars".length(), + b53857.length(), + "Chars"); // replace some of the end content + java.util.HashMap map53857 = new java.util.HashMap(); + map53857.put("key53857", b53857.toString()); // put in a collection + String c53857 = (String) map53857.get("key53857"); // get it back out + String d53857 = c53857.substring(0, c53857.length() - 1); // extract most of it + String e53857 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d53857.getBytes()))); // B64 encode and decode it + String f53857 = e53857.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f53857); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01617.java b/OWASP DATASET/BenchmarkTest01617.java new file mode 100644 index 0000000000000000000000000000000000000000..c31d1f6e338553b3c3ddeafb3e6a02b2846e27d6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01617.java @@ -0,0 +1,73 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01617") +public class BenchmarkTest01617 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01617"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String^,java.lang.Object) + request.getSession().setAttribute(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: '10340' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01618.java b/OWASP DATASET/BenchmarkTest01618.java new file mode 100644 index 0000000000000000000000000000000000000000..9a0fd89e8501c256233c7f66e1e51bff0d5826ab --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01618.java @@ -0,0 +1,72 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-00/BenchmarkTest01618") +public class BenchmarkTest01618 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01618"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01619.java b/OWASP DATASET/BenchmarkTest01619.java new file mode 100644 index 0000000000000000000000000000000000000000..26193557ce0853ac49a4e4975980e009c205b129 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01619.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest01619") +public class BenchmarkTest01619 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01619"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01620.java b/OWASP DATASET/BenchmarkTest01620.java new file mode 100644 index 0000000000000000000000000000000000000000..3c8f3ffba3128c07340e741420660008b2fc31ef --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01620.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01620") +public class BenchmarkTest01620 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01620"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = connection.prepareCall(sql); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01621.java b/OWASP DATASET/BenchmarkTest01621.java new file mode 100644 index 0000000000000000000000000000000000000000..e157229422025eff134418984ca7789ea2571c5c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01621.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01621") +public class BenchmarkTest01621 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01621"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01622.java b/OWASP DATASET/BenchmarkTest01622.java new file mode 100644 index 0000000000000000000000000000000000000000..14f6c6b3386f86a10244d69688e03f82edc5b8d9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01622.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01622") +public class BenchmarkTest01622 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01622"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01623.java b/OWASP DATASET/BenchmarkTest01623.java new file mode 100644 index 0000000000000000000000000000000000000000..9a8cc61f26c9b55a906df19ccc45a0803a20eb38 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01623.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01623") +public class BenchmarkTest01623 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01623"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01624.java b/OWASP DATASET/BenchmarkTest01624.java new file mode 100644 index 0000000000000000000000000000000000000000..da32c767da7278cba9770887c32ecea5dd26f6ae --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01624.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01624") +public class BenchmarkTest01624 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01624"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + // System.out.println("no results for query: " + sql + " because the Spring batchUpdate + // method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01625.java b/OWASP DATASET/BenchmarkTest01625.java new file mode 100644 index 0000000000000000000000000000000000000000..322b6f2e1fba94dc34de1799dda75052df36c74f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01625.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01625") +public class BenchmarkTest01625 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01625"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // Long results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForLong(sql); + Long results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Long.class); + response.getWriter().println("Your results are: " + String.valueOf(results)); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01626.java b/OWASP DATASET/BenchmarkTest01626.java new file mode 100644 index 0000000000000000000000000000000000000000..1b9f0c32715bfc17f0b6e160f4278e6e66f14593 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01626.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01626") +public class BenchmarkTest01626 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01626"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.addBatch(sql); + int[] counts = statement.executeBatch(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(sql, counts, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01627.java b/OWASP DATASET/BenchmarkTest01627.java new file mode 100644 index 0000000000000000000000000000000000000000..e94f0fe638aec57eb3ff751583370d34b466a06b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01627.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01627") +public class BenchmarkTest01627 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01627"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new String[] {"username", "password"}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01628.java b/OWASP DATASET/BenchmarkTest01628.java new file mode 100644 index 0000000000000000000000000000000000000000..3cc4796614092ba5b95d215e7ba9ae7ec6ba394a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01628.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01628") +public class BenchmarkTest01628 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01628"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new String[] {"username", "password"}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01629.java b/OWASP DATASET/BenchmarkTest01629.java new file mode 100644 index 0000000000000000000000000000000000000000..960f342be6cfaafb5cb335a060c1d339a60f63be --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01629.java @@ -0,0 +1,80 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01629") +public class BenchmarkTest01629 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01629"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01630.java b/OWASP DATASET/BenchmarkTest01630.java new file mode 100644 index 0000000000000000000000000000000000000000..25735ca49fb48577d7ccd6a0662a641d7a926980 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01630.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01630") +public class BenchmarkTest01630 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01630"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01631.java b/OWASP DATASET/BenchmarkTest01631.java new file mode 100644 index 0000000000000000000000000000000000000000..523623de6f2957273729b91f044a0a87f46b22f3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01631.java @@ -0,0 +1,80 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01631") +public class BenchmarkTest01631 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01631"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new String[] {"USERNAME", "PASSWORD"}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01632.java b/OWASP DATASET/BenchmarkTest01632.java new file mode 100644 index 0000000000000000000000000000000000000000..e773bb157d12b828a93d7deb3b15f72aa9655d4e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01632.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest01632") +public class BenchmarkTest01632 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01632"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + org.w3c.dom.NodeList nodeList = + (org.w3c.dom.NodeList) + xp.compile(expression) + .evaluate(xmlDocument, javax.xml.xpath.XPathConstants.NODESET); + + response.getWriter().println("Your query results are:
"); + + for (int i = 0; i < nodeList.getLength(); i++) { + org.w3c.dom.Element value = (org.w3c.dom.Element) nodeList.item(i); + response.getWriter().println(value.getTextContent() + "
"); + } + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01633.java b/OWASP DATASET/BenchmarkTest01633.java new file mode 100644 index 0000000000000000000000000000000000000000..35b1fef4e284db40f82618940b31ad5f96cf4f11 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01633.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest01633") +public class BenchmarkTest01633 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest01633"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = new Test().doSomething(request, param); + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + String result = xp.evaluate(expression, xmlDocument); + + response.getWriter().println("Your query results are: " + result + "
"); + + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a31144 = param; // assign + StringBuilder b31144 = new StringBuilder(a31144); // stick in stringbuilder + b31144.append(" SafeStuff"); // append some safe content + b31144.replace( + b31144.length() - "Chars".length(), + b31144.length(), + "Chars"); // replace some of the end content + java.util.HashMap map31144 = new java.util.HashMap(); + map31144.put("key31144", b31144.toString()); // put in a collection + String c31144 = (String) map31144.get("key31144"); // get it back out + String d31144 = c31144.substring(0, c31144.length() - 1); // extract most of it + String e31144 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d31144.getBytes()))); // B64 encode and decode it + String f31144 = e31144.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g31144 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g31144); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01634.java b/OWASP DATASET/BenchmarkTest01634.java new file mode 100644 index 0000000000000000000000000000000000000000..cd9787781d799a4327891ca05630a1b294df525f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01634.java @@ -0,0 +1,204 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01634") +public class BenchmarkTest01634 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01634" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01634" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01634" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "DES/CBC/PKCS5PADDING", java.security.Security.getProvider("SunJCE")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a37769 = param; // assign + StringBuilder b37769 = new StringBuilder(a37769); // stick in stringbuilder + b37769.append(" SafeStuff"); // append some safe content + b37769.replace( + b37769.length() - "Chars".length(), + b37769.length(), + "Chars"); // replace some of the end content + java.util.HashMap map37769 = new java.util.HashMap(); + map37769.put("key37769", b37769.toString()); // put in a collection + String c37769 = (String) map37769.get("key37769"); // get it back out + String d37769 = c37769.substring(0, c37769.length() - 1); // extract most of it + String e37769 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d37769.getBytes()))); // B64 encode and decode it + String f37769 = e37769.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g37769 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g37769); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01635.java b/OWASP DATASET/BenchmarkTest01635.java new file mode 100644 index 0000000000000000000000000000000000000000..7d084432c6a24a046cdfcc70118e7bd9b0c002e5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01635.java @@ -0,0 +1,186 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01635") +public class BenchmarkTest01635 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01635" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01635" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01635" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01636.java b/OWASP DATASET/BenchmarkTest01636.java new file mode 100644 index 0000000000000000000000000000000000000000..a320db7089c72914373a301c55fb1fad62838c88 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01636.java @@ -0,0 +1,185 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01636") +public class BenchmarkTest01636 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01636" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01636" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01636" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01637.java b/OWASP DATASET/BenchmarkTest01637.java new file mode 100644 index 0000000000000000000000000000000000000000..3cffab4551d44093ad24858f80a29993db569eab --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01637.java @@ -0,0 +1,206 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01637") +public class BenchmarkTest01637 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01637" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01637" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01637" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01638.java b/OWASP DATASET/BenchmarkTest01638.java new file mode 100644 index 0000000000000000000000000000000000000000..8865bed720d3a93975480c024bd540c6ad0cadbf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01638.java @@ -0,0 +1,173 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01638") +public class BenchmarkTest01638 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01638" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01638" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01638" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a61263 = param; // assign + StringBuilder b61263 = new StringBuilder(a61263); // stick in stringbuilder + b61263.append(" SafeStuff"); // append some safe content + b61263.replace( + b61263.length() - "Chars".length(), + b61263.length(), + "Chars"); // replace some of the end content + java.util.HashMap map61263 = new java.util.HashMap(); + map61263.put("key61263", b61263.toString()); // put in a collection + String c61263 = (String) map61263.get("key61263"); // get it back out + String d61263 = c61263.substring(0, c61263.length() - 1); // extract most of it + String e61263 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d61263.getBytes()))); // B64 encode and decode it + String f61263 = e61263.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f61263); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01639.java b/OWASP DATASET/BenchmarkTest01639.java new file mode 100644 index 0000000000000000000000000000000000000000..d15e7861d343039442d68bddcf91acbb5265e51f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01639.java @@ -0,0 +1,159 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01639") +public class BenchmarkTest01639 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01639" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01639" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01639" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map62111 = new java.util.HashMap(); + map62111.put("keyA-62111", "a_Value"); // put some stuff in the collection + map62111.put("keyB-62111", param); // put it in a collection + map62111.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map62111.get("keyB-62111"); // get it back out + bar = (String) map62111.get("keyA-62111"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01640.java b/OWASP DATASET/BenchmarkTest01640.java new file mode 100644 index 0000000000000000000000000000000000000000..16b0adc1ea3ab06e326bf6ed213a6b35552ec0f1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01640.java @@ -0,0 +1,164 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01640") +public class BenchmarkTest01640 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01640" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01640" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01640" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "AES/CCM/NoPadding", java.security.Security.getProvider("BC")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01641.java b/OWASP DATASET/BenchmarkTest01641.java new file mode 100644 index 0000000000000000000000000000000000000000..8734d13c72d3f55f2b664f8703f136c4c669e554 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01641.java @@ -0,0 +1,150 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01641") +public class BenchmarkTest01641 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01641" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01641" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01641" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map5640 = new java.util.HashMap(); + map5640.put("keyA-5640", "a_Value"); // put some stuff in the collection + map5640.put("keyB-5640", param); // put it in a collection + map5640.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map5640.get("keyB-5640"); // get it back out + bar = (String) map5640.get("keyA-5640"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01642.java b/OWASP DATASET/BenchmarkTest01642.java new file mode 100644 index 0000000000000000000000000000000000000000..5eabe20ee33cbc07a4fd445b66e617b3abc6cb61 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01642.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01642") +public class BenchmarkTest01642 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01642" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01642" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01642" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + java.io.File fileTarget = + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR, bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01643.java b/OWASP DATASET/BenchmarkTest01643.java new file mode 100644 index 0000000000000000000000000000000000000000..d3c196b45e07971cc232b461f3b5fbcc31f4456e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01643.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01643") +public class BenchmarkTest01643 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01643" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01643" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01643" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // FILE URIs are tricky because they are different between Mac and Windows because of lack + // of standardization. + // Mac requires an extra slash for some reason. + String startURIslashes = ""; + if (System.getProperty("os.name").indexOf("Windows") != -1) + if (System.getProperty("os.name").indexOf("Windows") != -1) startURIslashes = "/"; + else startURIslashes = "//"; + + try { + java.net.URI fileURI = + new java.net.URI( + "file:" + + startURIslashes + + org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + .replace('\\', '/') + .replace(' ', '_') + + bar); + java.io.File fileTarget = new java.io.File(fileURI); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } catch (java.net.URISyntaxException e) { + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01644.java b/OWASP DATASET/BenchmarkTest01644.java new file mode 100644 index 0000000000000000000000000000000000000000..4d70ed8e6c9848295656f0c5f345e1ec209f81ef --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01644.java @@ -0,0 +1,127 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01644") +public class BenchmarkTest01644 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01644" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01644" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01644" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(new java.io.File(fileName)); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting FileInputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01645.java b/OWASP DATASET/BenchmarkTest01645.java new file mode 100644 index 0000000000000000000000000000000000000000..2dbb225aecbbb7f19db56eff1dd47660c47d6089 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01645.java @@ -0,0 +1,131 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01645") +public class BenchmarkTest01645 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01645" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01645" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01645" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(fileName); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01646.java b/OWASP DATASET/BenchmarkTest01646.java new file mode 100644 index 0000000000000000000000000000000000000000..47c9515b0607288b3f31c844b677e2e67fb44894 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01646.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-01/BenchmarkTest01646") +public class BenchmarkTest01646 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01646" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01646" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01646" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName)); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map84260 = new java.util.HashMap(); + map84260.put("keyA-84260", "a_Value"); // put some stuff in the collection + map84260.put("keyB-84260", param); // put it in a collection + map84260.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map84260.get("keyB-84260"); // get it back out + bar = (String) map84260.get("keyA-84260"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01647.java b/OWASP DATASET/BenchmarkTest01647.java new file mode 100644 index 0000000000000000000000000000000000000000..26b25122475b2bfa8dfaac7f1e4eee5209ac3c6b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01647.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01647") +public class BenchmarkTest01647 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01647" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01647" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01647" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName, false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01648.java b/OWASP DATASET/BenchmarkTest01648.java new file mode 100644 index 0000000000000000000000000000000000000000..bed6b1e5f9c0d8e15f5fc59ce9034a3378c3c7c5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01648.java @@ -0,0 +1,132 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01648") +public class BenchmarkTest01648 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01648" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01648" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01648" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + double value = java.lang.Math.random(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Doug"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + response.getWriter().println("Weak Randomness Test java.lang.Math.random() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01649.java b/OWASP DATASET/BenchmarkTest01649.java new file mode 100644 index 0000000000000000000000000000000000000000..cc33d97520a9bcc180493fa81216ffc2367192bb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01649.java @@ -0,0 +1,143 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01649") +public class BenchmarkTest01649 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01649" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01649" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01649" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map61654 = new java.util.HashMap(); + map61654.put("keyA-61654", "a_Value"); // put some stuff in the collection + map61654.put("keyB-61654", param); // put it in a collection + map61654.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map61654.get("keyB-61654"); // get it back out + bar = (String) map61654.get("keyA-61654"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01650.java b/OWASP DATASET/BenchmarkTest01650.java new file mode 100644 index 0000000000000000000000000000000000000000..72af3bb65a3e60b8d824833b279d51bcc7ac8390 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01650.java @@ -0,0 +1,142 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01650") +public class BenchmarkTest01650 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01650" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01650" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01650" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01651.java b/OWASP DATASET/BenchmarkTest01651.java new file mode 100644 index 0000000000000000000000000000000000000000..6f0ff06e2da2c19b594843e08d1af4f6d0eefec5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01651.java @@ -0,0 +1,137 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01651") +public class BenchmarkTest01651 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01651" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01651" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01651" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01652.java b/OWASP DATASET/BenchmarkTest01652.java new file mode 100644 index 0000000000000000000000000000000000000000..12035e275508ac349f7bf9c87376efcc265cee5c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01652.java @@ -0,0 +1,144 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01652") +public class BenchmarkTest01652 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01652" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01652" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01652" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = + java.security.MessageDigest.getInstance("SHA-512", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map16429 = new java.util.HashMap(); + map16429.put("keyA-16429", "a_Value"); // put some stuff in the collection + map16429.put("keyB-16429", param); // put it in a collection + map16429.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map16429.get("keyB-16429"); // get it back out + bar = (String) map16429.get("keyA-16429"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01653.java b/OWASP DATASET/BenchmarkTest01653.java new file mode 100644 index 0000000000000000000000000000000000000000..ed415422e30a4d9effa9f9552bd2c58902e8af97 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01653.java @@ -0,0 +1,137 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01653") +public class BenchmarkTest01653 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01653" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01653" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01653" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01654.java b/OWASP DATASET/BenchmarkTest01654.java new file mode 100644 index 0000000000000000000000000000000000000000..3657413053acd4eb3b7b37415d75337eb101fbf8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01654.java @@ -0,0 +1,155 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01654") +public class BenchmarkTest01654 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01654" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01654" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01654" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01655.java b/OWASP DATASET/BenchmarkTest01655.java new file mode 100644 index 0000000000000000000000000000000000000000..b8fad12f2511c369841223045f3ad9557df54e17 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01655.java @@ -0,0 +1,141 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01655") +public class BenchmarkTest01655 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01655" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01655" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01655" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01656.java b/OWASP DATASET/BenchmarkTest01656.java new file mode 100644 index 0000000000000000000000000000000000000000..fbbcc88fa335f8bb3bfa0cad1fc517c55a99e084 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01656.java @@ -0,0 +1,155 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01656") +public class BenchmarkTest01656 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01656" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01656" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01656" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01657.java b/OWASP DATASET/BenchmarkTest01657.java new file mode 100644 index 0000000000000000000000000000000000000000..525af1e7f0a10687900150383ccbb2de11e1f7a7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01657.java @@ -0,0 +1,90 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01657") +public class BenchmarkTest01657 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01657" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01657" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01657" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + java.io.PrintWriter out = response.getWriter(); + out.write("\n\n\n

"); + out.format(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + out.write("\n

\n\n"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01658.java b/OWASP DATASET/BenchmarkTest01658.java new file mode 100644 index 0000000000000000000000000000000000000000..1d9cf59c87565772a92b62b44133d6eea971a8ab --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01658.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01658") +public class BenchmarkTest01658 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01658" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01658" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01658" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().format("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01659.java b/OWASP DATASET/BenchmarkTest01659.java new file mode 100644 index 0000000000000000000000000000000000000000..7d7bf6089664d7077caf66cd5ab46dda0f8f4949 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01659.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01659") +public class BenchmarkTest01659 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01659" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01659" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01659" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01660.java b/OWASP DATASET/BenchmarkTest01660.java new file mode 100644 index 0000000000000000000000000000000000000000..c5d51505a1c80cc9cbb11f4ac3ff4f4d9f02483d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01660.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01660") +public class BenchmarkTest01660 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01660" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01660" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01660" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01661.java b/OWASP DATASET/BenchmarkTest01661.java new file mode 100644 index 0000000000000000000000000000000000000000..14a0afdeb893ddde91ca39d3a7c81fefd7c5ed15 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01661.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01661") +public class BenchmarkTest01661 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01661" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01661" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01661" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01662.java b/OWASP DATASET/BenchmarkTest01662.java new file mode 100644 index 0000000000000000000000000000000000000000..73d1ec5d616f27a52780d734b7c0af5d45eb94c9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01662.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01662") +public class BenchmarkTest01662 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01662" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01662" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01662" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {bar, "b"}; + response.getWriter().printf("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01663.java b/OWASP DATASET/BenchmarkTest01663.java new file mode 100644 index 0000000000000000000000000000000000000000..023ccebc52ceb665b3a2c8098b87a24a3d1989d8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01663.java @@ -0,0 +1,93 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01663") +public class BenchmarkTest01663 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01663" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01663" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01663" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(bar, obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map36601 = new java.util.HashMap(); + map36601.put("keyA-36601", "a_Value"); // put some stuff in the collection + map36601.put("keyB-36601", param); // put it in a collection + map36601.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map36601.get("keyB-36601"); // get it back out + bar = (String) map36601.get("keyA-36601"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01664.java b/OWASP DATASET/BenchmarkTest01664.java new file mode 100644 index 0000000000000000000000000000000000000000..f7e69c8832cf3df14f8284486129c48833a973ca --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01664.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01664") +public class BenchmarkTest01664 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01664" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01664" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01664" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar.toCharArray()); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01665.java b/OWASP DATASET/BenchmarkTest01665.java new file mode 100644 index 0000000000000000000000000000000000000000..6748b4e55f2cfd216c6aa04c3718bbfe1f85dc16 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01665.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01665") +public class BenchmarkTest01665 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01665" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01665" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01665" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar.toCharArray()); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz55941 = new StringBuilder(param); + String bar = sbxyz55941.append("_SafeStuff").toString(); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01666.java b/OWASP DATASET/BenchmarkTest01666.java new file mode 100644 index 0000000000000000000000000000000000000000..89ac3fda7097e8bbb24b0d0f7afa2a9edff7ab2a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01666.java @@ -0,0 +1,93 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01666") +public class BenchmarkTest01666 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01666" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01666" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01666" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar.toCharArray()); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz41549 = new StringBuilder(param); + bar = + sbxyz41549 + .replace(param.length() - "Z".length(), param.length(), "Z") + .toString(); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01667.java b/OWASP DATASET/BenchmarkTest01667.java new file mode 100644 index 0000000000000000000000000000000000000000..dad76355a09ea67b27e2bee9fcc44b902a0a2898 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01667.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01667") +public class BenchmarkTest01667 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01667" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01667" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01667" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map96771 = new java.util.HashMap(); + map96771.put("keyA-96771", "a-Value"); // put some stuff in the collection + map96771.put("keyB-96771", param); // put it in a collection + map96771.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map96771.get("keyB-96771"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01668.java b/OWASP DATASET/BenchmarkTest01668.java new file mode 100644 index 0000000000000000000000000000000000000000..ecdbaa407c0c590e97dfd0e0f68455d8d981ab3e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01668.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01668") +public class BenchmarkTest01668 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01668" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01668" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01668" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map56839 = new java.util.HashMap(); + map56839.put("keyA-56839", "a_Value"); // put some stuff in the collection + map56839.put("keyB-56839", param); // put it in a collection + map56839.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map56839.get("keyB-56839"); // get it back out + bar = (String) map56839.get("keyA-56839"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01669.java b/OWASP DATASET/BenchmarkTest01669.java new file mode 100644 index 0000000000000000000000000000000000000000..e471470253a60edf3c648cfbc852d1e057c17222 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01669.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01669") +public class BenchmarkTest01669 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01669" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01669" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01669" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01670.java b/OWASP DATASET/BenchmarkTest01670.java new file mode 100644 index 0000000000000000000000000000000000000000..1ba647f95a557c34879ad80a11c538921b40f0af --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01670.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01670") +public class BenchmarkTest01670 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01670" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01670" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01670" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar.toCharArray()); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01671.java b/OWASP DATASET/BenchmarkTest01671.java new file mode 100644 index 0000000000000000000000000000000000000000..1a8e32a16ad36062b718d9af744899e761087914 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01671.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01671") +public class BenchmarkTest01671 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01671" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01671" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01671" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01672.java b/OWASP DATASET/BenchmarkTest01672.java new file mode 100644 index 0000000000000000000000000000000000000000..d4bdd945a17b1feccd5aba510b97aec04be999d4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01672.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01672") +public class BenchmarkTest01672 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01672" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01672" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01672" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String a1 = ""; + String a2 = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + } else { + a1 = "sh"; + a2 = "-c"; + } + String[] args = {a1, a2, "echo " + bar}; + + ProcessBuilder pb = new ProcessBuilder(); + + pb.command(args); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01673.java b/OWASP DATASET/BenchmarkTest01673.java new file mode 100644 index 0000000000000000000000000000000000000000..d51e0841af247718c39af0aeca54c7ce6aed9f73 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01673.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01673") +public class BenchmarkTest01673 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01673" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01673" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01673" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01674.java b/OWASP DATASET/BenchmarkTest01674.java new file mode 100644 index 0000000000000000000000000000000000000000..d2212faeb2413996eeb8d5b04fca90c2c629c918 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01674.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01674") +public class BenchmarkTest01674 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01674" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01674" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01674" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String a1 = ""; + String a2 = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + } else { + a1 = "sh"; + a2 = "-c"; + } + String[] args = {a1, a2, "echo " + bar}; + + ProcessBuilder pb = new ProcessBuilder(args); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.lang.String[]) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01675.java b/OWASP DATASET/BenchmarkTest01675.java new file mode 100644 index 0000000000000000000000000000000000000000..25cd7035f7980d1387d806c5ec0d28972dbb8eee --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01675.java @@ -0,0 +1,143 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01675") +public class BenchmarkTest01675 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01675" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01675" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01675" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + byte[] bytes = new byte[10]; + new java.util.Random().nextBytes(bytes); + String rememberMeKey = org.owasp.esapi.ESAPI.encoder().encodeForBase64(bytes, true); + + String user = "Byron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextBytes() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01676.java b/OWASP DATASET/BenchmarkTest01676.java new file mode 100644 index 0000000000000000000000000000000000000000..25480d57866805ba4cae926a0a2bf61685781a69 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01676.java @@ -0,0 +1,135 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01676") +public class BenchmarkTest01676 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01676" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01676" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01676" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + double value = new java.util.Random().nextDouble(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Donna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextDouble() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01677.java b/OWASP DATASET/BenchmarkTest01677.java new file mode 100644 index 0000000000000000000000000000000000000000..55d068a3deb72b422620ee78069a7761268fbb3b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01677.java @@ -0,0 +1,142 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01677") +public class BenchmarkTest01677 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01677" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01677" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01677" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + float rand = new java.util.Random().nextFloat(); + String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "Floyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01678.java b/OWASP DATASET/BenchmarkTest01678.java new file mode 100644 index 0000000000000000000000000000000000000000..439ee88bb31712c4c42a0fa3e5069744918b7929 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01678.java @@ -0,0 +1,152 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01678") +public class BenchmarkTest01678 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01678" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01678" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01678" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + float rand = new java.util.Random().nextFloat(); + String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "Floyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a96171 = param; // assign + StringBuilder b96171 = new StringBuilder(a96171); // stick in stringbuilder + b96171.append(" SafeStuff"); // append some safe content + b96171.replace( + b96171.length() - "Chars".length(), + b96171.length(), + "Chars"); // replace some of the end content + java.util.HashMap map96171 = new java.util.HashMap(); + map96171.put("key96171", b96171.toString()); // put in a collection + String c96171 = (String) map96171.get("key96171"); // get it back out + String d96171 = c96171.substring(0, c96171.length() - 1); // extract most of it + String e96171 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d96171.getBytes()))); // B64 encode and decode it + String f96171 = e96171.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f96171); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01679.java b/OWASP DATASET/BenchmarkTest01679.java new file mode 100644 index 0000000000000000000000000000000000000000..d25d7f33dbe065596548cd9470e46d620cc9d61d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01679.java @@ -0,0 +1,132 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01679") +public class BenchmarkTest01679 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01679" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01679" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01679" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + float rand = new java.util.Random().nextFloat(); + String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "Floyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01680.java b/OWASP DATASET/BenchmarkTest01680.java new file mode 100644 index 0000000000000000000000000000000000000000..3794521b32bd2abb9dbebc8f214eeda76900cd3c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01680.java @@ -0,0 +1,136 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01680") +public class BenchmarkTest01680 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01680" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01680" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01680" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + int randNumber = new java.util.Random().nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "Inga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt(int) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01681.java b/OWASP DATASET/BenchmarkTest01681.java new file mode 100644 index 0000000000000000000000000000000000000000..54cdff7f66ad6132c8465355f80b88402d1902c7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01681.java @@ -0,0 +1,137 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01681") +public class BenchmarkTest01681 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01681" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01681" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01681" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map97890 = new java.util.HashMap(); + map97890.put("keyA-97890", "a_Value"); // put some stuff in the collection + map97890.put("keyB-97890", param); // put it in a collection + map97890.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map97890.get("keyB-97890"); // get it back out + bar = (String) map97890.get("keyA-97890"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01682.java b/OWASP DATASET/BenchmarkTest01682.java new file mode 100644 index 0000000000000000000000000000000000000000..27620e03e58bd45c26ee266fcace1fab04297080 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01682.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest01682") +public class BenchmarkTest01682 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01682" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01682" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01682" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01683.java b/OWASP DATASET/BenchmarkTest01683.java new file mode 100644 index 0000000000000000000000000000000000000000..31ae7eaaef9ac32a14c82f173b01ae22138510f8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01683.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest01683") +public class BenchmarkTest01683 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01683" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01683" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01683" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01684.java b/OWASP DATASET/BenchmarkTest01684.java new file mode 100644 index 0000000000000000000000000000000000000000..00fd07db25e7cd079444d5aed61a58226ee7400e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01684.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest01684") +public class BenchmarkTest01684 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01684" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01684" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01684" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz77558 = new StringBuilder(param); + String bar = sbxyz77558.append("_SafeStuff").toString(); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01685.java b/OWASP DATASET/BenchmarkTest01685.java new file mode 100644 index 0000000000000000000000000000000000000000..a466ea995c9578a302697129f871160d731b412b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01685.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01685") +public class BenchmarkTest01685 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01685" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01685" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01685" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01686.java b/OWASP DATASET/BenchmarkTest01686.java new file mode 100644 index 0000000000000000000000000000000000000000..9f62864d687a412b6406f4f88d88d76056569913 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01686.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01686") +public class BenchmarkTest01686 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01686" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01686" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01686" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01687.java b/OWASP DATASET/BenchmarkTest01687.java new file mode 100644 index 0000000000000000000000000000000000000000..d862eb3c5207c3f0c0b285213a74aa87d6ff619a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01687.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01687") +public class BenchmarkTest01687 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01687" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01687" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01687" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01688.java b/OWASP DATASET/BenchmarkTest01688.java new file mode 100644 index 0000000000000000000000000000000000000000..16c23598f6e4564bde80052f8910f45106feb830 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01688.java @@ -0,0 +1,107 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01688") +public class BenchmarkTest01688 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01688" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01688" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01688" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01689.java b/OWASP DATASET/BenchmarkTest01689.java new file mode 100644 index 0000000000000000000000000000000000000000..b155a17bc515da7e7c9e91955329cf8d25156ba0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01689.java @@ -0,0 +1,107 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01689") +public class BenchmarkTest01689 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01689" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01689" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01689" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01690.java b/OWASP DATASET/BenchmarkTest01690.java new file mode 100644 index 0000000000000000000000000000000000000000..05599ba795b6d5ec2fb95763d897d4d9edb21ec4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01690.java @@ -0,0 +1,100 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01690") +public class BenchmarkTest01690 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01690" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01690" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01690" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01691.java b/OWASP DATASET/BenchmarkTest01691.java new file mode 100644 index 0000000000000000000000000000000000000000..81696f0532902eb2b7e955968c96b9d0f1380589 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01691.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-01/BenchmarkTest01691") +public class BenchmarkTest01691 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01691" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01691" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01691" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01692.java b/OWASP DATASET/BenchmarkTest01692.java new file mode 100644 index 0000000000000000000000000000000000000000..64f7ba42f87664beb2d1f260c22eb8f0274479a8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01692.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest01692") +public class BenchmarkTest01692 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01692" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01692" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01692" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = + r.exec(cmd + bar, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a28453 = param; // assign + StringBuilder b28453 = new StringBuilder(a28453); // stick in stringbuilder + b28453.append(" SafeStuff"); // append some safe content + b28453.replace( + b28453.length() - "Chars".length(), + b28453.length(), + "Chars"); // replace some of the end content + java.util.HashMap map28453 = new java.util.HashMap(); + map28453.put("key28453", b28453.toString()); // put in a collection + String c28453 = (String) map28453.get("key28453"); // get it back out + String d28453 = c28453.substring(0, c28453.length() - 1); // extract most of it + String e28453 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d28453.getBytes()))); // B64 encode and decode it + String f28453 = e28453.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g28453 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g28453); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01693.java b/OWASP DATASET/BenchmarkTest01693.java new file mode 100644 index 0000000000000000000000000000000000000000..6ae983ced7110cd05967ff819a22fe1103546c4b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01693.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest01693") +public class BenchmarkTest01693 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01693" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01693" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01693" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = + r.exec(cmd + bar, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01694.java b/OWASP DATASET/BenchmarkTest01694.java new file mode 100644 index 0000000000000000000000000000000000000000..196f3068e01fcdc9dc54d3b07d26568bee6f407c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01694.java @@ -0,0 +1,146 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01694") +public class BenchmarkTest01694 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01694" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01694" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01694" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01695.java b/OWASP DATASET/BenchmarkTest01695.java new file mode 100644 index 0000000000000000000000000000000000000000..361a011708dea99a1ff968897e10122669ae5846 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01695.java @@ -0,0 +1,154 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01695") +public class BenchmarkTest01695 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01695" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01695" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01695" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + getNextNumber(numGen, randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeBystander"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + void getNextNumber(java.util.Random generator, byte[] barray) { + generator.nextBytes(barray); + } + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01696.java b/OWASP DATASET/BenchmarkTest01696.java new file mode 100644 index 0000000000000000000000000000000000000000..5d87ccc458826631950a4090f8b6b60573798d11 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01696.java @@ -0,0 +1,145 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01696") +public class BenchmarkTest01696 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01696" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01696" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01696" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map83181 = new java.util.HashMap(); + map83181.put("keyA-83181", "a-Value"); // put some stuff in the collection + map83181.put("keyB-83181", param); // put it in a collection + map83181.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map83181.get("keyB-83181"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01697.java b/OWASP DATASET/BenchmarkTest01697.java new file mode 100644 index 0000000000000000000000000000000000000000..a2b2cde26c24baaf6a993eaa90e84cb714bbf9f4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01697.java @@ -0,0 +1,141 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01697") +public class BenchmarkTest01697 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01697" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01697" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01697" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz19197 = new StringBuilder(param); + String bar = sbxyz19197.append("_SafeStuff").toString(); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01698.java b/OWASP DATASET/BenchmarkTest01698.java new file mode 100644 index 0000000000000000000000000000000000000000..7bccf765b7f127b6d4c5ad21efbfa6135ffcab07 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01698.java @@ -0,0 +1,166 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01698") +public class BenchmarkTest01698 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01698" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01698" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01698" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + double rand = getNextNumber(numGen); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonatella"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + double getNextNumber(java.util.Random generator) { + return generator.nextDouble(); + } + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a72232 = param; // assign + StringBuilder b72232 = new StringBuilder(a72232); // stick in stringbuilder + b72232.append(" SafeStuff"); // append some safe content + b72232.replace( + b72232.length() - "Chars".length(), + b72232.length(), + "Chars"); // replace some of the end content + java.util.HashMap map72232 = new java.util.HashMap(); + map72232.put("key72232", b72232.toString()); // put in a collection + String c72232 = (String) map72232.get("key72232"); // get it back out + String d72232 = c72232.substring(0, c72232.length() - 1); // extract most of it + String e72232 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d72232.getBytes()))); // B64 encode and decode it + String f72232 = e72232.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g72232 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g72232); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01699.java b/OWASP DATASET/BenchmarkTest01699.java new file mode 100644 index 0000000000000000000000000000000000000000..394f7f741fa5cca1408a93faf21e018d028c4319 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01699.java @@ -0,0 +1,145 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01699") +public class BenchmarkTest01699 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01699" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01699" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01699" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + double rand = getNextNumber(numGen); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonatella"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + double getNextNumber(java.util.Random generator) { + return generator.nextDouble(); + } + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01700.java b/OWASP DATASET/BenchmarkTest01700.java new file mode 100644 index 0000000000000000000000000000000000000000..f411962af40160b551b81a1c49b6fd9cae91a9c2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01700.java @@ -0,0 +1,164 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01700") +public class BenchmarkTest01700 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01700" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01700" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01700" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + double rand = getNextNumber(numGen); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonatella"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + double getNextNumber(java.util.Random generator) { + return generator.nextDouble(); + } + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01701.java b/OWASP DATASET/BenchmarkTest01701.java new file mode 100644 index 0000000000000000000000000000000000000000..6269dec90df3b85d06823b8c4b3d4919bedb485b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01701.java @@ -0,0 +1,142 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01701") +public class BenchmarkTest01701 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01701" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01701" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01701" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01702.java b/OWASP DATASET/BenchmarkTest01702.java new file mode 100644 index 0000000000000000000000000000000000000000..7873eb7e73bfe7afb5c6dc38a981e9bdd3cdab85 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01702.java @@ -0,0 +1,143 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01702") +public class BenchmarkTest01702 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01702" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01702" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01702" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01703.java b/OWASP DATASET/BenchmarkTest01703.java new file mode 100644 index 0000000000000000000000000000000000000000..41570cea38ab52c4b0abdfccf3d33258ef2cf9e0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01703.java @@ -0,0 +1,145 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01703") +public class BenchmarkTest01703 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01703" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01703" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01703" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + float rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextFloat(); + String rememberMeKey = + Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeFloyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextFloat() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextFloat() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01704.java b/OWASP DATASET/BenchmarkTest01704.java new file mode 100644 index 0000000000000000000000000000000000000000..415ef1504433d6d67be2d109efb7dcf72f7aee46 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01704.java @@ -0,0 +1,142 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01704") +public class BenchmarkTest01704 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01704" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01704" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01704" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + int randNumber = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "SafeInga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt(int) - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt(int) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01705.java b/OWASP DATASET/BenchmarkTest01705.java new file mode 100644 index 0000000000000000000000000000000000000000..1812f73b5eb2741b365ddd3b2d2c1e17de03bdb1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01705.java @@ -0,0 +1,142 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01705") +public class BenchmarkTest01705 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01705" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01705" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01705" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + int randNumber = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "SafeInga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt(int) - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt(int) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01706.java b/OWASP DATASET/BenchmarkTest01706.java new file mode 100644 index 0000000000000000000000000000000000000000..734511fe49a89e6a53ea06fe72b391f2d357f20f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01706.java @@ -0,0 +1,137 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01706") +public class BenchmarkTest01706 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01706" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01706" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01706" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + int r = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "SafeIngrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01707.java b/OWASP DATASET/BenchmarkTest01707.java new file mode 100644 index 0000000000000000000000000000000000000000..dd9ba8548a6eefeccf5df645f952ade9bc42d351 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01707.java @@ -0,0 +1,142 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01707") +public class BenchmarkTest01707 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01707" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01707" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01707" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + int r = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "SafeIngrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map13101 = new java.util.HashMap(); + map13101.put("keyA-13101", "a-Value"); // put some stuff in the collection + map13101.put("keyB-13101", param); // put it in a collection + map13101.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map13101.get("keyB-13101"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01708.java b/OWASP DATASET/BenchmarkTest01708.java new file mode 100644 index 0000000000000000000000000000000000000000..626972abceb809e0f0f5ab36523bc3567b5034ac --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01708.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest01708") +public class BenchmarkTest01708 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01708" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01708" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01708" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String^,java.lang.Object) + request.getSession().putValue(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: 10340 saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01709.java b/OWASP DATASET/BenchmarkTest01709.java new file mode 100644 index 0000000000000000000000000000000000000000..2043c4372f4757fe3a1271476df37415d5155a9c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01709.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest01709") +public class BenchmarkTest01709 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01709" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01709" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01709" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a15574 = param; // assign + StringBuilder b15574 = new StringBuilder(a15574); // stick in stringbuilder + b15574.append(" SafeStuff"); // append some safe content + b15574.replace( + b15574.length() - "Chars".length(), + b15574.length(), + "Chars"); // replace some of the end content + java.util.HashMap map15574 = new java.util.HashMap(); + map15574.put("key15574", b15574.toString()); // put in a collection + String c15574 = (String) map15574.get("key15574"); // get it back out + String d15574 = c15574.substring(0, c15574.length() - 1); // extract most of it + String e15574 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d15574.getBytes()))); // B64 encode and decode it + String f15574 = e15574.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f15574); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01710.java b/OWASP DATASET/BenchmarkTest01710.java new file mode 100644 index 0000000000000000000000000000000000000000..a54111ea7d8b78e6cb34432b18bff7c2bb4026bb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01710.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest01710") +public class BenchmarkTest01710 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01710" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01710" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01710" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01711.java b/OWASP DATASET/BenchmarkTest01711.java new file mode 100644 index 0000000000000000000000000000000000000000..a38168907a8dee3f7e72d9f8251b2ed7001831de --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01711.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest01711") +public class BenchmarkTest01711 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01711" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01711" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01711" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01712.java b/OWASP DATASET/BenchmarkTest01712.java new file mode 100644 index 0000000000000000000000000000000000000000..07b5a4ed5e27d1537233ddd81da572ee7c21061f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01712.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01712") +public class BenchmarkTest01712 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01712" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01712" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01712" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = connection.prepareCall(sql); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map6261 = new java.util.HashMap(); + map6261.put("keyA-6261", "a-Value"); // put some stuff in the collection + map6261.put("keyB-6261", param); // put it in a collection + map6261.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map6261.get("keyB-6261"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01713.java b/OWASP DATASET/BenchmarkTest01713.java new file mode 100644 index 0000000000000000000000000000000000000000..d0929cc2a800be8586e1099a8f2aa7beb66ae8fe --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01713.java @@ -0,0 +1,105 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01713") +public class BenchmarkTest01713 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01713" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01713" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01713" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = connection.prepareCall(sql); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map83939 = new java.util.HashMap(); + map83939.put("keyA-83939", "a_Value"); // put some stuff in the collection + map83939.put("keyB-83939", param); // put it in a collection + map83939.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map83939.get("keyB-83939"); // get it back out + bar = (String) map83939.get("keyA-83939"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01714.java b/OWASP DATASET/BenchmarkTest01714.java new file mode 100644 index 0000000000000000000000000000000000000000..916429eabf92dedc501a322e629b0aa5a2cabb21 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01714.java @@ -0,0 +1,107 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01714") +public class BenchmarkTest01714 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01714" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01714" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01714" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01715.java b/OWASP DATASET/BenchmarkTest01715.java new file mode 100644 index 0000000000000000000000000000000000000000..853147f3a63a9182715b42da8fb8624476e967f2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01715.java @@ -0,0 +1,105 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01715") +public class BenchmarkTest01715 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01715" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01715" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01715" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01716.java b/OWASP DATASET/BenchmarkTest01716.java new file mode 100644 index 0000000000000000000000000000000000000000..41666d1b2894a0dc059c5a1fc2b5dc88f75e4905 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01716.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01716") +public class BenchmarkTest01716 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01716" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01716" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01716" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01717.java b/OWASP DATASET/BenchmarkTest01717.java new file mode 100644 index 0000000000000000000000000000000000000000..434aadd3475817beb26d3060fc7744e4a6bad555 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01717.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01717") +public class BenchmarkTest01717 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01717" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01717" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01717" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01718.java b/OWASP DATASET/BenchmarkTest01718.java new file mode 100644 index 0000000000000000000000000000000000000000..d3e9e5ee3f70d4f330987d035504b915f9a92c91 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01718.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01718") +public class BenchmarkTest01718 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01718" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01718" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01718" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01719.java b/OWASP DATASET/BenchmarkTest01719.java new file mode 100644 index 0000000000000000000000000000000000000000..50596e9f63c82b01e7094d8dfda774b426b95bb7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01719.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01719") +public class BenchmarkTest01719 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01719" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01719" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01719" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, new String[] {"Column1", "Column2"}); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01720.java b/OWASP DATASET/BenchmarkTest01720.java new file mode 100644 index 0000000000000000000000000000000000000000..66a65076132c21e4a964ad9b677aad385322d232 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01720.java @@ -0,0 +1,105 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01720") +public class BenchmarkTest01720 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01720" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01720" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01720" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.execute(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring execute method doesn't return results."); + + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01721.java b/OWASP DATASET/BenchmarkTest01721.java new file mode 100644 index 0000000000000000000000000000000000000000..80fa7ce887409c01d7ee61b84d1c2c59504ac08b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01721.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01721") +public class BenchmarkTest01721 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01721" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01721" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01721" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.query( + sql, + new org.springframework.jdbc.core.RowMapper() { + @Override + public String mapRow(java.sql.ResultSet rs, int rowNum) + throws java.sql.SQLException { + try { + return rs.getString("USERNAME"); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper + .hideSQLErrors) { + return "Error processing query."; + } else throw e; + } + } + }); + response.getWriter().println("Your results are: "); + + for (String s : results) { + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(s) + "
"); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01722.java b/OWASP DATASET/BenchmarkTest01722.java new file mode 100644 index 0000000000000000000000000000000000000000..a77e7fca4d220268e5c66c1c79bb5d689556f5c8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01722.java @@ -0,0 +1,125 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01722") +public class BenchmarkTest01722 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01722" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01722" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01722" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.query( + sql, + new org.springframework.jdbc.core.RowMapper() { + @Override + public String mapRow(java.sql.ResultSet rs, int rowNum) + throws java.sql.SQLException { + try { + return rs.getString("USERNAME"); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper + .hideSQLErrors) { + return "Error processing query."; + } else throw e; + } + } + }); + response.getWriter().println("Your results are: "); + + for (String s : results) { + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(s) + "
"); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map33422 = new java.util.HashMap(); + map33422.put("keyA-33422", "a_Value"); // put some stuff in the collection + map33422.put("keyB-33422", param); // put it in a collection + map33422.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map33422.get("keyB-33422"); // get it back out + bar = (String) map33422.get("keyA-33422"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01723.java b/OWASP DATASET/BenchmarkTest01723.java new file mode 100644 index 0000000000000000000000000000000000000000..0de6e9b5badae4593ca1cbe1b6abc9f653556919 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01723.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01723") +public class BenchmarkTest01723 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01723" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01723" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01723" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // int results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForInt(sql); + Integer results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Integer.class); + response.getWriter().println("Your results are: " + results); + // System.out.println("Your results are: " + results); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01724.java b/OWASP DATASET/BenchmarkTest01724.java new file mode 100644 index 0000000000000000000000000000000000000000..15c84684360f989b75e95a49c08a5937a164b0a2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01724.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01724") +public class BenchmarkTest01724 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01724" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01724" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01724" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List> list = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForList(sql); + response.getWriter().println("Your results are:
"); + + // System.out.println("Your results are"); + + for (Object o : list) { + response.getWriter() + .println( + org.owasp.esapi.ESAPI.encoder().encodeForHTML(o.toString()) + + "
"); + // System.out.println(o.toString()); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01725.java b/OWASP DATASET/BenchmarkTest01725.java new file mode 100644 index 0000000000000000000000000000000000000000..1d1cac9ccb030e6f7c794d076550a58ddcb7af8a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01725.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01725") +public class BenchmarkTest01725 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01725" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01725" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01725" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = + "SELECT TOP 1 USERNAME from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + Object results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, new Object[] {}, String.class); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(results.toString())); + // System.out.println(results.toString()); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01726.java b/OWASP DATASET/BenchmarkTest01726.java new file mode 100644 index 0000000000000000000000000000000000000000..e73791235cdaa4160b5015d3ceb5ad97d75dc77f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01726.java @@ -0,0 +1,131 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01726") +public class BenchmarkTest01726 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01726" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01726" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01726" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + org.springframework.jdbc.support.rowset.SqlRowSet results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForRowSet(sql); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + while (results.next()) { + response.getWriter() + .println( + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(results.getString("USERNAME")) + + " "); + // System.out.println(results.getString("USERNAME")); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01727.java b/OWASP DATASET/BenchmarkTest01727.java new file mode 100644 index 0000000000000000000000000000000000000000..0f9fa34241fd2718c9d65c659f8c764cb7e0bb7f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01727.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01727") +public class BenchmarkTest01727 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01727" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01727" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01727" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01728.java b/OWASP DATASET/BenchmarkTest01728.java new file mode 100644 index 0000000000000000000000000000000000000000..f22735fa6649ee2cbcf5d12fb82695768fe198c9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01728.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01728") +public class BenchmarkTest01728 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01728" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01728" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01728" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.addBatch(sql); + int[] counts = statement.executeBatch(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(sql, counts, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01729.java b/OWASP DATASET/BenchmarkTest01729.java new file mode 100644 index 0000000000000000000000000000000000000000..d7828b29e615130de2c920338c9211d44a85107e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01729.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01729") +public class BenchmarkTest01729 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01729" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01729" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01729" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.addBatch(sql); + int[] counts = statement.executeBatch(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(sql, counts, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01730.java b/OWASP DATASET/BenchmarkTest01730.java new file mode 100644 index 0000000000000000000000000000000000000000..f2b8d067576dac84bd178d34b9a3e7142c01e5b0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01730.java @@ -0,0 +1,107 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01730") +public class BenchmarkTest01730 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01730" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01730" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01730" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01731.java b/OWASP DATASET/BenchmarkTest01731.java new file mode 100644 index 0000000000000000000000000000000000000000..dd30be2aeba237af3aa76bef76c90644b58d0e39 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01731.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01731") +public class BenchmarkTest01731 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01731" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01731" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01731" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new String[] {"username", "password"}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01732.java b/OWASP DATASET/BenchmarkTest01732.java new file mode 100644 index 0000000000000000000000000000000000000000..8681e815ad983d4db2cfdd0b6aeb1f56ff83376f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01732.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01732") +public class BenchmarkTest01732 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01732" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01732" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01732" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + java.sql.ResultSet rs = statement.executeQuery(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01733.java b/OWASP DATASET/BenchmarkTest01733.java new file mode 100644 index 0000000000000000000000000000000000000000..4f5644ab3c529ab7167b5f5c391913b68366a8db --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01733.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01733") +public class BenchmarkTest01733 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01733" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01733" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01733" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new String[] {"USERNAME", "PASSWORD"}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01734.java b/OWASP DATASET/BenchmarkTest01734.java new file mode 100644 index 0000000000000000000000000000000000000000..76cde95480fa59f94873d339d05108e509344fd9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01734.java @@ -0,0 +1,125 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest01734") +public class BenchmarkTest01734 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01734" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01734" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01734" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + org.w3c.dom.NodeList nodeList = + (org.w3c.dom.NodeList) + xp.compile(expression) + .evaluate(xmlDocument, javax.xml.xpath.XPathConstants.NODESET); + + response.getWriter().println("Your query results are:
"); + + for (int i = 0; i < nodeList.getLength(); i++) { + org.w3c.dom.Element value = (org.w3c.dom.Element) nodeList.item(i); + response.getWriter().println(value.getTextContent() + "
"); + } + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01735.java b/OWASP DATASET/BenchmarkTest01735.java new file mode 100644 index 0000000000000000000000000000000000000000..786e24e8ecadab804ee8d74b4461aac08f842210 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01735.java @@ -0,0 +1,125 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest01735") +public class BenchmarkTest01735 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01735" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01735" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01735" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + org.w3c.dom.NodeList nodeList = + (org.w3c.dom.NodeList) + xp.compile(expression) + .evaluate(xmlDocument, javax.xml.xpath.XPathConstants.NODESET); + + response.getWriter().println("Your query results are:
"); + + for (int i = 0; i < nodeList.getLength(); i++) { + org.w3c.dom.Element value = (org.w3c.dom.Element) nodeList.item(i); + response.getWriter().println(value.getTextContent() + "
"); + } + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01736.java b/OWASP DATASET/BenchmarkTest01736.java new file mode 100644 index 0000000000000000000000000000000000000000..68b7b04c145177a2d728c7cc1d5a294780344f41 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01736.java @@ -0,0 +1,123 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest01736") +public class BenchmarkTest01736 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest01736" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest01736" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest01736" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = new Test().doSomething(request, param); + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + String result = xp.evaluate(expression, xmlDocument); + + response.getWriter().println("Your query results are: " + result + "
"); + + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01737.java b/OWASP DATASET/BenchmarkTest01737.java new file mode 100644 index 0000000000000000000000000000000000000000..99a43cd32c0957f37384c2821002e31c3674243b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01737.java @@ -0,0 +1,161 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01737") +public class BenchmarkTest01737 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01737"); + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01738.java b/OWASP DATASET/BenchmarkTest01738.java new file mode 100644 index 0000000000000000000000000000000000000000..27e689460de92c48468fcd9a9279eab2b3b880bd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01738.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01738") +public class BenchmarkTest01738 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01738"); + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = org.owasp.benchmark.helpers.Utils.getCipher(); + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01739.java b/OWASP DATASET/BenchmarkTest01739.java new file mode 100644 index 0000000000000000000000000000000000000000..fbbedc52a4cb8bc5decc4ed43e5a09f70ba965f9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01739.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01739") +public class BenchmarkTest01739 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01739"); + + String bar = new Test().doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = org.owasp.benchmark.helpers.Utils.getCipher(); + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz60534 = new StringBuilder(param); + String bar = sbxyz60534.append("_SafeStuff").toString(); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01740.java b/OWASP DATASET/BenchmarkTest01740.java new file mode 100644 index 0000000000000000000000000000000000000000..5acc479bd6e36a2a5e667f31e2ccbf74d80a9e05 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01740.java @@ -0,0 +1,122 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01740") +public class BenchmarkTest01740 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01740"); + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01741.java b/OWASP DATASET/BenchmarkTest01741.java new file mode 100644 index 0000000000000000000000000000000000000000..2423b94d48ddd4205b003d9e37193a1ad3b3ffef --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01741.java @@ -0,0 +1,128 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01741") +public class BenchmarkTest01741 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01741"); + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz82048 = new StringBuilder(param); + bar = + sbxyz82048 + .replace(param.length() - "Z".length(), param.length(), "Z") + .toString(); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01742.java b/OWASP DATASET/BenchmarkTest01742.java new file mode 100644 index 0000000000000000000000000000000000000000..173ab1b90aeb9162cfa151225ff98afb9d15fa0d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01742.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01742") +public class BenchmarkTest01742 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01742"); + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01743.java b/OWASP DATASET/BenchmarkTest01743.java new file mode 100644 index 0000000000000000000000000000000000000000..908ecc844aed299c939800a4d783132e6076fd3e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01743.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest01743") +public class BenchmarkTest01743 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01743"); + + String bar = new Test().doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + javax.naming.directory.DirContext ctx = ads.getDirContext(); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + bar + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + // System.out.println("Filter " + filter); + boolean found = false; + javax.naming.NamingEnumeration results = + ctx.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01744.java b/OWASP DATASET/BenchmarkTest01744.java new file mode 100644 index 0000000000000000000000000000000000000000..423ac23184d6c8715f75f45c55b4a8aed96a5615 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01744.java @@ -0,0 +1,98 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01744") +public class BenchmarkTest01744 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01744"); + + String bar = new Test().doSomething(request, param); + + java.io.File fileTarget = + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR, bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a17402 = param; // assign + StringBuilder b17402 = new StringBuilder(a17402); // stick in stringbuilder + b17402.append(" SafeStuff"); // append some safe content + b17402.replace( + b17402.length() - "Chars".length(), + b17402.length(), + "Chars"); // replace some of the end content + java.util.HashMap map17402 = new java.util.HashMap(); + map17402.put("key17402", b17402.toString()); // put in a collection + String c17402 = (String) map17402.get("key17402"); // get it back out + String d17402 = c17402.substring(0, c17402.length() - 1); // extract most of it + String e17402 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d17402.getBytes()))); // B64 encode and decode it + String f17402 = e17402.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g17402 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g17402); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01745.java b/OWASP DATASET/BenchmarkTest01745.java new file mode 100644 index 0000000000000000000000000000000000000000..2c835c36736b51c4317af179c2f927cf14d36304 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01745.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01745") +public class BenchmarkTest01745 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01745"); + + String bar = new Test().doSomething(request, param); + + java.io.File fileTarget = new java.io.File(bar, "/Test.txt"); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01746.java b/OWASP DATASET/BenchmarkTest01746.java new file mode 100644 index 0000000000000000000000000000000000000000..09176a01142636cd3532758e17a7ac308ee5df6f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01746.java @@ -0,0 +1,101 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01746") +public class BenchmarkTest01746 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01746"); + + String bar = new Test().doSomething(request, param); + + // FILE URIs are tricky because they are different between Mac and Windows because of lack + // of standardization. + // Mac requires an extra slash for some reason. + String startURIslashes = ""; + if (System.getProperty("os.name").indexOf("Windows") != -1) + if (System.getProperty("os.name").indexOf("Windows") != -1) startURIslashes = "/"; + else startURIslashes = "//"; + + try { + java.net.URI fileURI = + new java.net.URI( + "file:" + + startURIslashes + + org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + .replace('\\', '/') + .replace(' ', '_') + + bar); + java.io.File fileTarget = new java.io.File(fileURI); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } catch (java.net.URISyntaxException e) { + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01747.java b/OWASP DATASET/BenchmarkTest01747.java new file mode 100644 index 0000000000000000000000000000000000000000..56792f4baa5fed29ce1dfa40db82b8e4acebf8f8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01747.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01747") +public class BenchmarkTest01747 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01747"); + + String bar = new Test().doSomething(request, param); + + // FILE URIs are tricky because they are different between Mac and Windows because of lack + // of standardization. + // Mac requires an extra slash for some reason. + String startURIslashes = ""; + if (System.getProperty("os.name").indexOf("Windows") != -1) + if (System.getProperty("os.name").indexOf("Windows") != -1) startURIslashes = "/"; + else startURIslashes = "//"; + + try { + java.net.URI fileURI = + new java.net.URI( + "file", + null, + startURIslashes + + org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + .replace('\\', java.io.File.separatorChar) + .replace(' ', '_') + + bar, + null, + null); + java.io.File fileTarget = new java.io.File(fileURI); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } catch (java.net.URISyntaxException e) { + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01748.java b/OWASP DATASET/BenchmarkTest01748.java new file mode 100644 index 0000000000000000000000000000000000000000..05d03b8466d578d96f306106fde046501dfd0ace --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01748.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01748") +public class BenchmarkTest01748 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01748"); + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(new java.io.File(fileName)); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting FileInputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01749.java b/OWASP DATASET/BenchmarkTest01749.java new file mode 100644 index 0000000000000000000000000000000000000000..0a1664e0a370aa842a7a727d169b2ce32b2d2d11 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01749.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01749") +public class BenchmarkTest01749 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01749"); + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(new java.io.File(fileName)); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting FileInputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01750.java b/OWASP DATASET/BenchmarkTest01750.java new file mode 100644 index 0000000000000000000000000000000000000000..2cd4b888fb4e1b546e3f816165b6d93f94a2a196 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01750.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01750") +public class BenchmarkTest01750 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01750"); + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(fileName); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01751.java b/OWASP DATASET/BenchmarkTest01751.java new file mode 100644 index 0000000000000000000000000000000000000000..3b780b2dd5debd56071838f89de4d31eacf96d73 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01751.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01751") +public class BenchmarkTest01751 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01751"); + + String bar = new Test().doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName), false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01752.java b/OWASP DATASET/BenchmarkTest01752.java new file mode 100644 index 0000000000000000000000000000000000000000..524866aa463370ee524de40a573458f522e01e19 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01752.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01752") +public class BenchmarkTest01752 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01752"); + + String bar = new Test().doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + try ( + // Create the file first so the test won't throw an exception if it doesn't exist. + // Note: Don't actually do this because this method signature could cause a tool to find + // THIS file constructor + // as a vuln, rather than the File signature we are trying to actually test. + // If necessary, just run the benchmark twice. The 1st run should create all the necessary + // files. + // new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar).createNewFile(); + + java.io.FileOutputStream fos = + new java.io.FileOutputStream(new java.io.FileInputStream(fileName).getFD()); ) { + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map11351 = new java.util.HashMap(); + map11351.put("keyA-11351", "a-Value"); // put some stuff in the collection + map11351.put("keyB-11351", param); // put it in a collection + map11351.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map11351.get("keyB-11351"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01753.java b/OWASP DATASET/BenchmarkTest01753.java new file mode 100644 index 0000000000000000000000000000000000000000..0cc45bff7f88f3006a43572b4d8d6a90e77b458f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01753.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest01753") +public class BenchmarkTest01753 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01753"); + + String bar = new Test().doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + bar + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + + javax.naming.directory.DirContext ctx = ads.getDirContext(); + javax.naming.directory.InitialDirContext idc = + (javax.naming.directory.InitialDirContext) ctx; + boolean found = false; + javax.naming.NamingEnumeration results = + idc.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01754.java b/OWASP DATASET/BenchmarkTest01754.java new file mode 100644 index 0000000000000000000000000000000000000000..a9b09462553dfbd1a4d33fb5afb3682d55866627 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01754.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest01754") +public class BenchmarkTest01754 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01754"); + + String bar = new Test().doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + bar + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + + javax.naming.directory.DirContext ctx = ads.getDirContext(); + javax.naming.directory.InitialDirContext idc = + (javax.naming.directory.InitialDirContext) ctx; + boolean found = false; + javax.naming.NamingEnumeration results = + idc.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map91865 = new java.util.HashMap(); + map91865.put("keyA-91865", "a-Value"); // put some stuff in the collection + map91865.put("keyB-91865", param); // put it in a collection + map91865.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map91865.get("keyB-91865"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01755.java b/OWASP DATASET/BenchmarkTest01755.java new file mode 100644 index 0000000000000000000000000000000000000000..7dbbae0442f3ce80d707aec6c039141ed7b22208 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01755.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest01755") +public class BenchmarkTest01755 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01755"); + + String bar = new Test().doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person)(uid=" + bar + "))"; + + javax.naming.directory.DirContext ctx = ads.getDirContext(); + javax.naming.directory.InitialDirContext idc = + (javax.naming.directory.InitialDirContext) ctx; + boolean found = false; + javax.naming.NamingEnumeration results = + idc.search(base, filter, sc); + + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map69635 = new java.util.HashMap(); + map69635.put("keyA-69635", "a-Value"); // put some stuff in the collection + map69635.put("keyB-69635", param); // put it in a collection + map69635.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map69635.get("keyB-69635"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01756.java b/OWASP DATASET/BenchmarkTest01756.java new file mode 100644 index 0000000000000000000000000000000000000000..f8ea3256971ade50f61e32b9c4e56a55c23018e3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01756.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest01756") +public class BenchmarkTest01756 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01756"); + + String bar = new Test().doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person)(uid=" + bar + "))"; + + javax.naming.directory.DirContext ctx = ads.getDirContext(); + javax.naming.directory.InitialDirContext idc = + (javax.naming.directory.InitialDirContext) ctx; + boolean found = false; + javax.naming.NamingEnumeration results = + idc.search(base, filter, sc); + + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01757.java b/OWASP DATASET/BenchmarkTest01757.java new file mode 100644 index 0000000000000000000000000000000000000000..189c58bbd675eb7af9ff94b99e30bb98e5ba0420 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01757.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01757") +public class BenchmarkTest01757 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01757"); + + String bar = new Test().doSomething(request, param); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("SHA1", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01758.java b/OWASP DATASET/BenchmarkTest01758.java new file mode 100644 index 0000000000000000000000000000000000000000..812696b21bbfd44a867b499648ce40ea19afd5aa --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01758.java @@ -0,0 +1,127 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01758") +public class BenchmarkTest01758 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01758"); + + String bar = new Test().doSomething(request, param); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("sha-384", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("sha-384", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01759.java b/OWASP DATASET/BenchmarkTest01759.java new file mode 100644 index 0000000000000000000000000000000000000000..8b9430117d13b5c91dbb7f95b175255dae4dc948 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01759.java @@ -0,0 +1,122 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-01/BenchmarkTest01759") +public class BenchmarkTest01759 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01759"); + + String bar = new Test().doSomething(request, param); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("sha-384", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("sha-384", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01760.java b/OWASP DATASET/BenchmarkTest01760.java new file mode 100644 index 0000000000000000000000000000000000000000..15d84e639aadeaf5c8573f7027242d23f504f4d3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01760.java @@ -0,0 +1,141 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest01760") +public class BenchmarkTest01760 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01760"); + + String bar = new Test().doSomething(request, param); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("sha-384", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("sha-384", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01761.java b/OWASP DATASET/BenchmarkTest01761.java new file mode 100644 index 0000000000000000000000000000000000000000..ed6f6b10851751ac454ac712755f854be6375ebd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01761.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest01761") +public class BenchmarkTest01761 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01761"); + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01762.java b/OWASP DATASET/BenchmarkTest01762.java new file mode 100644 index 0000000000000000000000000000000000000000..087fda15fc713cc5c8122df7dcb9f3cc68ebfa2c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01762.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest01762") +public class BenchmarkTest01762 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01762"); + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-256"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01763.java b/OWASP DATASET/BenchmarkTest01763.java new file mode 100644 index 0000000000000000000000000000000000000000..31bbf69c76102392edc6d2181f7613f28a1b966b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01763.java @@ -0,0 +1,111 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest01763") +public class BenchmarkTest01763 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01763"); + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-256"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01764.java b/OWASP DATASET/BenchmarkTest01764.java new file mode 100644 index 0000000000000000000000000000000000000000..fc842382cb5f1d5c59a227a38fb267d199ef3f8a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01764.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest01764") +public class BenchmarkTest01764 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01764"); + + String bar = new Test().doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-256"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01765.java b/OWASP DATASET/BenchmarkTest01765.java new file mode 100644 index 0000000000000000000000000000000000000000..fbf30d1f2af67cc9a4d3401bae9c4193fbcd01ef --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01765.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest01765") +public class BenchmarkTest01765 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01765"); + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01766.java b/OWASP DATASET/BenchmarkTest01766.java new file mode 100644 index 0000000000000000000000000000000000000000..c113d21a23b51fd09aeb9ba32d275f3aeb9698d0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01766.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest01766") +public class BenchmarkTest01766 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01766"); + + String bar = new Test().doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01767.java b/OWASP DATASET/BenchmarkTest01767.java new file mode 100644 index 0000000000000000000000000000000000000000..5656d504dc84350f979ddc42b74c95d0eda4fdcc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01767.java @@ -0,0 +1,69 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01767") +public class BenchmarkTest01767 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01767"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(java.util.Locale.US, bar, obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01768.java b/OWASP DATASET/BenchmarkTest01768.java new file mode 100644 index 0000000000000000000000000000000000000000..b019e5389bc8d5e528cb7058ab06140bb239dc28 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01768.java @@ -0,0 +1,65 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01768") +public class BenchmarkTest01768 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01768"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().format("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01769.java b/OWASP DATASET/BenchmarkTest01769.java new file mode 100644 index 0000000000000000000000000000000000000000..9006bbce526ddd3ae5534843266c6f956b154798 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01769.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01769") +public class BenchmarkTest01769 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01769"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(java.util.Locale.US, bar, obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01770.java b/OWASP DATASET/BenchmarkTest01770.java new file mode 100644 index 0000000000000000000000000000000000000000..dd694a0b6fbadebdfafd810e23f30841c6d5a8bb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01770.java @@ -0,0 +1,65 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01770") +public class BenchmarkTest01770 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01770"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(bar, obj); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz41282 = new StringBuilder(param); + String bar = sbxyz41282.append("_SafeStuff").toString(); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01771.java b/OWASP DATASET/BenchmarkTest01771.java new file mode 100644 index 0000000000000000000000000000000000000000..1078d4bda44770548059d8b7a8055cd1810f8000 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01771.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01771") +public class BenchmarkTest01771 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01771"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a58724 = param; // assign + StringBuilder b58724 = new StringBuilder(a58724); // stick in stringbuilder + b58724.append(" SafeStuff"); // append some safe content + b58724.replace( + b58724.length() - "Chars".length(), + b58724.length(), + "Chars"); // replace some of the end content + java.util.HashMap map58724 = new java.util.HashMap(); + map58724.put("key58724", b58724.toString()); // put in a collection + String c58724 = (String) map58724.get("key58724"); // get it back out + String d58724 = c58724.substring(0, c58724.length() - 1); // extract most of it + String e58724 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d58724.getBytes()))); // B64 encode and decode it + String f58724 = e58724.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f58724); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01772.java b/OWASP DATASET/BenchmarkTest01772.java new file mode 100644 index 0000000000000000000000000000000000000000..db1a1eadebe5843155a8206a82fc8d9716b9ef7d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01772.java @@ -0,0 +1,64 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01772") +public class BenchmarkTest01772 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01772"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar.toCharArray()); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz76680 = new StringBuilder(param); + String bar = sbxyz76680.append("_SafeStuff").toString(); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01773.java b/OWASP DATASET/BenchmarkTest01773.java new file mode 100644 index 0000000000000000000000000000000000000000..5c5dd96033460aee8d8112b7799085731855cdfd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01773.java @@ -0,0 +1,67 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01773") +public class BenchmarkTest01773 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01773"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar.toCharArray(), 0, length); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01774.java b/OWASP DATASET/BenchmarkTest01774.java new file mode 100644 index 0000000000000000000000000000000000000000..8cac42f65d0d24d8a88f4e0a0fb8eba74c780c08 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01774.java @@ -0,0 +1,69 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01774") +public class BenchmarkTest01774 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01774"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map58318 = new java.util.HashMap(); + map58318.put("keyA-58318", "a_Value"); // put some stuff in the collection + map58318.put("keyB-58318", param); // put it in a collection + map58318.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map58318.get("keyB-58318"); // get it back out + bar = (String) map58318.get("keyA-58318"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01775.java b/OWASP DATASET/BenchmarkTest01775.java new file mode 100644 index 0000000000000000000000000000000000000000..81122baebe11fb59c558621d6c2ba7e51c2c8f13 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01775.java @@ -0,0 +1,68 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01775") +public class BenchmarkTest01775 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01775"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01776.java b/OWASP DATASET/BenchmarkTest01776.java new file mode 100644 index 0000000000000000000000000000000000000000..f8d7c2e7e378a3c7f49b02b21b8857a11ce9c7b3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01776.java @@ -0,0 +1,73 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01776") +public class BenchmarkTest01776 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01776"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar, 0, length); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map3531 = new java.util.HashMap(); + map3531.put("keyA-3531", "a_Value"); // put some stuff in the collection + map3531.put("keyB-3531", param); // put it in a collection + map3531.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map3531.get("keyB-3531"); // get it back out + bar = (String) map3531.get("keyA-3531"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01777.java b/OWASP DATASET/BenchmarkTest01777.java new file mode 100644 index 0000000000000000000000000000000000000000..b90dec65237743d1658f575a38b9708f983a478e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01777.java @@ -0,0 +1,72 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01777") +public class BenchmarkTest01777 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01777"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar, 0, length); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01778.java b/OWASP DATASET/BenchmarkTest01778.java new file mode 100644 index 0000000000000000000000000000000000000000..07631e4d6d62a72f2e438fa2ebcce04356b016f9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01778.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest01778") +public class BenchmarkTest01778 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01778"); + + String bar = new Test().doSomething(request, param); + + String a1 = ""; + String a2 = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + } else { + a1 = "sh"; + a2 = "-c"; + } + String[] args = {a1, a2, "echo " + bar}; + + ProcessBuilder pb = new ProcessBuilder(); + + pb.command(args); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01779.java b/OWASP DATASET/BenchmarkTest01779.java new file mode 100644 index 0000000000000000000000000000000000000000..fbd29c6eccb25193169a0f7e5982a5fc8c31dcf8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01779.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest01779") +public class BenchmarkTest01779 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01779"); + + String bar = new Test().doSomething(request, param); + + String a1 = ""; + String a2 = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + } else { + a1 = "sh"; + a2 = "-c"; + } + String[] args = {a1, a2, "echo " + bar}; + + ProcessBuilder pb = new ProcessBuilder(); + + pb.command(args); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01780.java b/OWASP DATASET/BenchmarkTest01780.java new file mode 100644 index 0000000000000000000000000000000000000000..66a6362c18fc3757dc492ca73744a0565e3ae410 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01780.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest01780") +public class BenchmarkTest01780 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01780"); + + String bar = new Test().doSomething(request, param); + + String a1 = ""; + String a2 = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + } else { + a1 = "sh"; + a2 = "-c"; + } + String[] args = {a1, a2, "echo " + bar}; + + ProcessBuilder pb = new ProcessBuilder(args); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.lang.String[]) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map90655 = new java.util.HashMap(); + map90655.put("keyA-90655", "a_Value"); // put some stuff in the collection + map90655.put("keyB-90655", param); // put it in a collection + map90655.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map90655.get("keyB-90655"); // get it back out + bar = (String) map90655.get("keyA-90655"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01781.java b/OWASP DATASET/BenchmarkTest01781.java new file mode 100644 index 0000000000000000000000000000000000000000..7f86beb62822a1ba0779b8beaac1d2d5cbb357d3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01781.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01781") +public class BenchmarkTest01781 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01781"); + + String bar = new Test().doSomething(request, param); + + double value = new java.util.Random().nextDouble(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Donna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextDouble() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01782.java b/OWASP DATASET/BenchmarkTest01782.java new file mode 100644 index 0000000000000000000000000000000000000000..b0b2bf4519bf98934df7fee3066f204990792789 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01782.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01782") +public class BenchmarkTest01782 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01782"); + + String bar = new Test().doSomething(request, param); + + double stuff = new java.util.Random().nextGaussian(); + String rememberMeKey = Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "Gayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter() + .println("Weak Randomness Test java.util.Random.nextGaussian() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01783.java b/OWASP DATASET/BenchmarkTest01783.java new file mode 100644 index 0000000000000000000000000000000000000000..f62e0471c9bc53007304d3ad5200554bf7ed2219 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01783.java @@ -0,0 +1,111 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01783") +public class BenchmarkTest01783 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01783"); + + String bar = new Test().doSomething(request, param); + + double stuff = new java.util.Random().nextGaussian(); + String rememberMeKey = Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "Gayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter() + .println("Weak Randomness Test java.util.Random.nextGaussian() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01784.java b/OWASP DATASET/BenchmarkTest01784.java new file mode 100644 index 0000000000000000000000000000000000000000..b111ad6e145241e52bd322312dfccde5d3811a3a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01784.java @@ -0,0 +1,118 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01784") +public class BenchmarkTest01784 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01784"); + + String bar = new Test().doSomething(request, param); + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01785.java b/OWASP DATASET/BenchmarkTest01785.java new file mode 100644 index 0000000000000000000000000000000000000000..d3d012faf8ae2df9105e080706e604757d992451 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01785.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01785") +public class BenchmarkTest01785 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01785"); + + String bar = new Test().doSomething(request, param); + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01786.java b/OWASP DATASET/BenchmarkTest01786.java new file mode 100644 index 0000000000000000000000000000000000000000..3166859a5fbc70e864cb8f14afb60e77240bce7a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01786.java @@ -0,0 +1,118 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01786") +public class BenchmarkTest01786 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01786"); + + String bar = new Test().doSomething(request, param); + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01787.java b/OWASP DATASET/BenchmarkTest01787.java new file mode 100644 index 0000000000000000000000000000000000000000..03bdfc988f97d2b8413d8a45109f91fecd12b252 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01787.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-03/BenchmarkTest01787") +public class BenchmarkTest01787 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01787"); + + String bar = new Test().doSomething(request, param); + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01788.java b/OWASP DATASET/BenchmarkTest01788.java new file mode 100644 index 0000000000000000000000000000000000000000..47410321f8ae5bf69973886679a515600852c724 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01788.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01788") +public class BenchmarkTest01788 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01788"); + + String bar = new Test().doSomething(request, param); + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01789.java b/OWASP DATASET/BenchmarkTest01789.java new file mode 100644 index 0000000000000000000000000000000000000000..755bfc25b133999e9fa09acd4b12da713ffa81af --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01789.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest01789") +public class BenchmarkTest01789 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01789"); + + String bar = new Test().doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01790.java b/OWASP DATASET/BenchmarkTest01790.java new file mode 100644 index 0000000000000000000000000000000000000000..24770caae87570d731f0d316ccdd21a7be6c31fa --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01790.java @@ -0,0 +1,63 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01790") +public class BenchmarkTest01790 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01790"); + + String bar = new Test().doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write("Parameter value: " + bar); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01791.java b/OWASP DATASET/BenchmarkTest01791.java new file mode 100644 index 0000000000000000000000000000000000000000..d1e1c6dac5ab29849ae5c00eb67bf4c646fa385d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01791.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest01791") +public class BenchmarkTest01791 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01791"); + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01792.java b/OWASP DATASET/BenchmarkTest01792.java new file mode 100644 index 0000000000000000000000000000000000000000..2951336ed4ca0c3d5a77ebb9afeff4554c1fded0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01792.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest01792") +public class BenchmarkTest01792 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01792"); + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01793.java b/OWASP DATASET/BenchmarkTest01793.java new file mode 100644 index 0000000000000000000000000000000000000000..6ca03a3d8ec3aef71d88dd739554ea40ed9b9ca6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01793.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest01793") +public class BenchmarkTest01793 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01793"); + + String bar = new Test().doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01794.java b/OWASP DATASET/BenchmarkTest01794.java new file mode 100644 index 0000000000000000000000000000000000000000..f8b8874ea0d413eece4d327ca72a9c7696574629 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01794.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest01794") +public class BenchmarkTest01794 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01794"); + + String bar = new Test().doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01795.java b/OWASP DATASET/BenchmarkTest01795.java new file mode 100644 index 0000000000000000000000000000000000000000..260283df3a7718d9f16d7d3f8b52ea283f236918 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01795.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest01795") +public class BenchmarkTest01795 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01795"); + + String bar = new Test().doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01796.java b/OWASP DATASET/BenchmarkTest01796.java new file mode 100644 index 0000000000000000000000000000000000000000..a89ff96910e9d617e2570bb292495105030c7f51 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01796.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest01796") +public class BenchmarkTest01796 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01796"); + + String bar = new Test().doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01797.java b/OWASP DATASET/BenchmarkTest01797.java new file mode 100644 index 0000000000000000000000000000000000000000..f5e51901b5a50156983a75b7ecb957aa4995849b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01797.java @@ -0,0 +1,123 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01797") +public class BenchmarkTest01797 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01797"); + + String bar = new Test().doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map85341 = new java.util.HashMap(); + map85341.put("keyA-85341", "a_Value"); // put some stuff in the collection + map85341.put("keyB-85341", param); // put it in a collection + map85341.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map85341.get("keyB-85341"); // get it back out + bar = (String) map85341.get("keyA-85341"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01798.java b/OWASP DATASET/BenchmarkTest01798.java new file mode 100644 index 0000000000000000000000000000000000000000..6c3a3f964eeee72ccd6077e613216ed369fdc337 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01798.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01798") +public class BenchmarkTest01798 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01798"); + + String bar = new Test().doSomething(request, param); + + try { + float rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextFloat(); + String rememberMeKey = + Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeFloyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextFloat() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextFloat() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01799.java b/OWASP DATASET/BenchmarkTest01799.java new file mode 100644 index 0000000000000000000000000000000000000000..ce57305699aa0732de70b36389e8d9bbf0e5fa16 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01799.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01799") +public class BenchmarkTest01799 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01799"); + + String bar = new Test().doSomething(request, param); + + try { + float rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextFloat(); + String rememberMeKey = + Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeFloyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextFloat() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextFloat() executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01800.java b/OWASP DATASET/BenchmarkTest01800.java new file mode 100644 index 0000000000000000000000000000000000000000..ecf3d16501a696ca8a6d0b80ac8d6cfd459f7499 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01800.java @@ -0,0 +1,134 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01800") +public class BenchmarkTest01800 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01800"); + + String bar = new Test().doSomething(request, param); + + try { + int randNumber = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "SafeInga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt(int) - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt(int) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a71684 = param; // assign + StringBuilder b71684 = new StringBuilder(a71684); // stick in stringbuilder + b71684.append(" SafeStuff"); // append some safe content + b71684.replace( + b71684.length() - "Chars".length(), + b71684.length(), + "Chars"); // replace some of the end content + java.util.HashMap map71684 = new java.util.HashMap(); + map71684.put("key71684", b71684.toString()); // put in a collection + String c71684 = (String) map71684.get("key71684"); // get it back out + String d71684 = c71684.substring(0, c71684.length() - 1); // extract most of it + String e71684 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d71684.getBytes()))); // B64 encode and decode it + String f71684 = e71684.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f71684); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01801.java b/OWASP DATASET/BenchmarkTest01801.java new file mode 100644 index 0000000000000000000000000000000000000000..3ba42841919f34b097d8f6be8860a4bdd38695c5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01801.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01801") +public class BenchmarkTest01801 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01801"); + + String bar = new Test().doSomething(request, param); + + try { + int randNumber = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "SafeInga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt(int) - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt(int) executed"); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01802.java b/OWASP DATASET/BenchmarkTest01802.java new file mode 100644 index 0000000000000000000000000000000000000000..619076d3e2a4833e708c75345af81e058e7bddd3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01802.java @@ -0,0 +1,69 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest01802") +public class BenchmarkTest01802 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01802"); + + String bar = new Test().doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String^,java.lang.Object) + request.getSession().putValue(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: 10340 saved in session."); + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01803.java b/OWASP DATASET/BenchmarkTest01803.java new file mode 100644 index 0000000000000000000000000000000000000000..b610d3dcf080c4bf26af0a4e23b5ef4fda22db1e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01803.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01803") +public class BenchmarkTest01803 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01803"); + + String bar = new Test().doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = connection.prepareCall(sql); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01804.java b/OWASP DATASET/BenchmarkTest01804.java new file mode 100644 index 0000000000000000000000000000000000000000..fb6da6d9c538f943b87508750bd5216828510110 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01804.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01804") +public class BenchmarkTest01804 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01804"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = connection.prepareStatement(sql); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map31481 = new java.util.HashMap(); + map31481.put("keyA-31481", "a_Value"); // put some stuff in the collection + map31481.put("keyB-31481", param); // put it in a collection + map31481.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map31481.get("keyB-31481"); // get it back out + bar = (String) map31481.get("keyA-31481"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01805.java b/OWASP DATASET/BenchmarkTest01805.java new file mode 100644 index 0000000000000000000000000000000000000000..bb7d83eae7f342de9bed50b8cedf42b9d3a80baf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01805.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01805") +public class BenchmarkTest01805 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01805"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map10271 = new java.util.HashMap(); + map10271.put("keyA-10271", "a_Value"); // put some stuff in the collection + map10271.put("keyB-10271", param); // put it in a collection + map10271.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map10271.get("keyB-10271"); // get it back out + bar = (String) map10271.get("keyA-10271"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01806.java b/OWASP DATASET/BenchmarkTest01806.java new file mode 100644 index 0000000000000000000000000000000000000000..5afa5f23b4122b39561e6faab46172044a943aea --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01806.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01806") +public class BenchmarkTest01806 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01806"); + + String bar = new Test().doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + // System.out.println("no results for query: " + sql + " because the Spring batchUpdate + // method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01807.java b/OWASP DATASET/BenchmarkTest01807.java new file mode 100644 index 0000000000000000000000000000000000000000..307a8ee06c71bc0fa6cee104298380988bbc21cd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01807.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01807") +public class BenchmarkTest01807 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01807"); + + String bar = new Test().doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + // System.out.println("no results for query: " + sql + " because the Spring batchUpdate + // method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01808.java b/OWASP DATASET/BenchmarkTest01808.java new file mode 100644 index 0000000000000000000000000000000000000000..278e6b2679c595900fef66274dc5d501e459a751 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01808.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01808") +public class BenchmarkTest01808 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01808"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // int results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForInt(sql); + Integer results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Integer.class); + response.getWriter().println("Your results are: " + results); + // System.out.println("Your results are: " + results); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01809.java b/OWASP DATASET/BenchmarkTest01809.java new file mode 100644 index 0000000000000000000000000000000000000000..0d21da2b1d80fdf49cea1bdfcab22a41f7c23538 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01809.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01809") +public class BenchmarkTest01809 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01809"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List> list = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForList(sql); + response.getWriter().println("Your results are:
"); + + // System.out.println("Your results are"); + + for (Object o : list) { + response.getWriter() + .println( + org.owasp.esapi.ESAPI.encoder().encodeForHTML(o.toString()) + + "
"); + // System.out.println(o.toString()); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a64594 = param; // assign + StringBuilder b64594 = new StringBuilder(a64594); // stick in stringbuilder + b64594.append(" SafeStuff"); // append some safe content + b64594.replace( + b64594.length() - "Chars".length(), + b64594.length(), + "Chars"); // replace some of the end content + java.util.HashMap map64594 = new java.util.HashMap(); + map64594.put("key64594", b64594.toString()); // put in a collection + String c64594 = (String) map64594.get("key64594"); // get it back out + String d64594 = c64594.substring(0, c64594.length() - 1); // extract most of it + String e64594 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d64594.getBytes()))); // B64 encode and decode it + String f64594 = e64594.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g64594 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g64594); // reflection + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01810.java b/OWASP DATASET/BenchmarkTest01810.java new file mode 100644 index 0000000000000000000000000000000000000000..1a083344fce096a1709b97357fdb182bcf8b32d5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01810.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01810") +public class BenchmarkTest01810 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01810"); + + String bar = new Test().doSomething(request, param); + + String sql = + "SELECT TOP 1 userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.Map results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForMap(sql); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(results.toString())); + // System.out.println(results.toString()); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01811.java b/OWASP DATASET/BenchmarkTest01811.java new file mode 100644 index 0000000000000000000000000000000000000000..6a01a19c0641ece01d3072705b277b361cfdeafa --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01811.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01811") +public class BenchmarkTest01811 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01811"); + + String bar = new Test().doSomething(request, param); + + String sql = + "SELECT TOP 1 userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.Map results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForMap(sql); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(results.toString())); + // System.out.println(results.toString()); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map31047 = new java.util.HashMap(); + map31047.put("keyA-31047", "a_Value"); // put some stuff in the collection + map31047.put("keyB-31047", param); // put it in a collection + map31047.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map31047.get("keyB-31047"); // get it back out + bar = (String) map31047.get("keyA-31047"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01812.java b/OWASP DATASET/BenchmarkTest01812.java new file mode 100644 index 0000000000000000000000000000000000000000..2e880806d016fc330a96623e4fa7e08464f58cbe --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01812.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01812") +public class BenchmarkTest01812 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01812"); + + String bar = new Test().doSomething(request, param); + + String sql = + "SELECT TOP 1 USERNAME from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + Object results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, new Object[] {}, String.class); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(results.toString())); + // System.out.println(results.toString()); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map20703 = new java.util.HashMap(); + map20703.put("keyA-20703", "a_Value"); // put some stuff in the collection + map20703.put("keyB-20703", param); // put it in a collection + map20703.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map20703.get("keyB-20703"); // get it back out + bar = (String) map20703.get("keyA-20703"); // get safe value back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01813.java b/OWASP DATASET/BenchmarkTest01813.java new file mode 100644 index 0000000000000000000000000000000000000000..aed1088376089228ff4b4c3895bf5fe87d45962a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01813.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-03/BenchmarkTest01813") +public class BenchmarkTest01813 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01813"); + + String bar = new Test().doSomething(request, param); + + String sql = + "SELECT TOP 1 USERNAME from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + Object results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, new Object[] {}, String.class); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(results.toString())); + // System.out.println(results.toString()); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01814.java b/OWASP DATASET/BenchmarkTest01814.java new file mode 100644 index 0000000000000000000000000000000000000000..1908204d72dfdbb1600541285771dd2f45bc7a73 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01814.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01814") +public class BenchmarkTest01814 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01814"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + org.springframework.jdbc.support.rowset.SqlRowSet results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForRowSet(sql); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + while (results.next()) { + response.getWriter() + .println( + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(results.getString("USERNAME")) + + " "); + // System.out.println(results.getString("USERNAME")); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01815.java b/OWASP DATASET/BenchmarkTest01815.java new file mode 100644 index 0000000000000000000000000000000000000000..527192ca85e519db7398e8c84aa3af40bb89b250 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01815.java @@ -0,0 +1,80 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01815") +public class BenchmarkTest01815 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01815"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.addBatch(sql); + int[] counts = statement.executeBatch(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(sql, counts, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map72704 = new java.util.HashMap(); + map72704.put("keyA-72704", "a-Value"); // put some stuff in the collection + map72704.put("keyB-72704", param); // put it in a collection + map72704.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map72704.get("keyB-72704"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01816.java b/OWASP DATASET/BenchmarkTest01816.java new file mode 100644 index 0000000000000000000000000000000000000000..37f6cd4c41c1a8dbe6296e756e58f022eaaa37c2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01816.java @@ -0,0 +1,80 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01816") +public class BenchmarkTest01816 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01816"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.addBatch(sql); + int[] counts = statement.executeBatch(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(sql, counts, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01817.java b/OWASP DATASET/BenchmarkTest01817.java new file mode 100644 index 0000000000000000000000000000000000000000..54e1bb776a4dc5060d4aef08f9d002ab61520284 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01817.java @@ -0,0 +1,80 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01817") +public class BenchmarkTest01817 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01817"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.addBatch(sql); + int[] counts = statement.executeBatch(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(sql, counts, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01818.java b/OWASP DATASET/BenchmarkTest01818.java new file mode 100644 index 0000000000000000000000000000000000000000..b3ef628ad6574bee90da47c2cb6e55cb4f8a8e4a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01818.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01818") +public class BenchmarkTest01818 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01818"); + + String bar = new Test().doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01819.java b/OWASP DATASET/BenchmarkTest01819.java new file mode 100644 index 0000000000000000000000000000000000000000..4b9ee78d8f12b5ccff84f29475cf90446eefea1e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01819.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01819") +public class BenchmarkTest01819 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01819"); + + String bar = new Test().doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map64759 = new java.util.HashMap(); + map64759.put("keyA-64759", "a-Value"); // put some stuff in the collection + map64759.put("keyB-64759", param); // put it in a collection + map64759.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map64759.get("keyB-64759"); // get it back out + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01820.java b/OWASP DATASET/BenchmarkTest01820.java new file mode 100644 index 0000000000000000000000000000000000000000..905b70a0ca7d0f01dda3d3a168e7bb515c356bbf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01820.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01820") +public class BenchmarkTest01820 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01820"); + + String bar = new Test().doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new String[] {"USERNAME", "PASSWORD"}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01821.java b/OWASP DATASET/BenchmarkTest01821.java new file mode 100644 index 0000000000000000000000000000000000000000..c74d6262e6a2e3b1fc20cc3ab6728100dd05c242 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01821.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Dave Wichers + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest01821") +public class BenchmarkTest01821 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest01821"); + + String bar = new Test().doSomething(request, param); + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + String result = xp.evaluate(expression, xmlDocument); + + response.getWriter().println("Your query results are: " + result + "
"); + + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } // end doPost + + private class Test { + + public String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } + } // end innerclass Test +} // end DataflowThruInnerClass diff --git a/OWASP DATASET/BenchmarkTest01822.java b/OWASP DATASET/BenchmarkTest01822.java new file mode 100644 index 0000000000000000000000000000000000000000..652063479fe991cffe6092106393f4fbffaddbe0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01822.java @@ -0,0 +1,180 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01822") +public class BenchmarkTest01822 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01822", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/crypto-02/BenchmarkTest01822.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01822")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "DES/CBC/PKCS5PADDING", java.security.Security.getProvider("SunJCE")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map20550 = new java.util.HashMap(); + map20550.put("keyA-20550", "a-Value"); // put some stuff in the collection + map20550.put("keyB-20550", param); // put it in a collection + map20550.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map20550.get("keyB-20550"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01823.java b/OWASP DATASET/BenchmarkTest01823.java new file mode 100644 index 0000000000000000000000000000000000000000..14b27319655be4324781fd939ed2a9b89046c4c0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01823.java @@ -0,0 +1,180 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01823") +public class BenchmarkTest01823 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01823", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/crypto-02/BenchmarkTest01823.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01823")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "DES/CBC/PKCS5PADDING", java.security.Security.getProvider("SunJCE")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01824.java b/OWASP DATASET/BenchmarkTest01824.java new file mode 100644 index 0000000000000000000000000000000000000000..faa6c3b76b4f26504a2034aee4e068f59e18133a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01824.java @@ -0,0 +1,176 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01824") +public class BenchmarkTest01824 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01824", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/crypto-02/BenchmarkTest01824.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01824")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01825.java b/OWASP DATASET/BenchmarkTest01825.java new file mode 100644 index 0000000000000000000000000000000000000000..3c9e3444780856546e399867164299c8de5b9834 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01825.java @@ -0,0 +1,181 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01825") +public class BenchmarkTest01825 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01825", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/crypto-02/BenchmarkTest01825.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01825")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01826.java b/OWASP DATASET/BenchmarkTest01826.java new file mode 100644 index 0000000000000000000000000000000000000000..ed98148017a8dde521c4d88cb6d7a54af9ddb4f6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01826.java @@ -0,0 +1,182 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01826") +public class BenchmarkTest01826 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01826", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/crypto-02/BenchmarkTest01826.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01826")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map38565 = new java.util.HashMap(); + map38565.put("keyA-38565", "a_Value"); // put some stuff in the collection + map38565.put("keyB-38565", param); // put it in a collection + map38565.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map38565.get("keyB-38565"); // get it back out + bar = (String) map38565.get("keyA-38565"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01827.java b/OWASP DATASET/BenchmarkTest01827.java new file mode 100644 index 0000000000000000000000000000000000000000..1a0206901d1b5bfa4b4303567c6ca2ed2788cb32 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01827.java @@ -0,0 +1,195 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01827") +public class BenchmarkTest01827 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01827", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/crypto-02/BenchmarkTest01827.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01827")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01828.java b/OWASP DATASET/BenchmarkTest01828.java new file mode 100644 index 0000000000000000000000000000000000000000..c3f800b1fff25e9e06a737f0abc5e25661ffece0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01828.java @@ -0,0 +1,136 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01828") +public class BenchmarkTest01828 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01828", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/crypto-02/BenchmarkTest01828.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01828")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = org.owasp.benchmark.helpers.Utils.getCipher(); + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz6675 = new StringBuilder(param); + String bar = sbxyz6675.append("_SafeStuff").toString(); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01829.java b/OWASP DATASET/BenchmarkTest01829.java new file mode 100644 index 0000000000000000000000000000000000000000..dc5d3143b11eaf0f028ad4a4422155f1ff7b12c2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01829.java @@ -0,0 +1,156 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01829") +public class BenchmarkTest01829 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01829", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/crypto-02/BenchmarkTest01829.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01829")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a60792 = param; // assign + StringBuilder b60792 = new StringBuilder(a60792); // stick in stringbuilder + b60792.append(" SafeStuff"); // append some safe content + b60792.replace( + b60792.length() - "Chars".length(), + b60792.length(), + "Chars"); // replace some of the end content + java.util.HashMap map60792 = new java.util.HashMap(); + map60792.put("key60792", b60792.toString()); // put in a collection + String c60792 = (String) map60792.get("key60792"); // get it back out + String d60792 = c60792.substring(0, c60792.length() - 1); // extract most of it + String e60792 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d60792.getBytes()))); // B64 encode and decode it + String f60792 = e60792.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f60792); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01830.java b/OWASP DATASET/BenchmarkTest01830.java new file mode 100644 index 0000000000000000000000000000000000000000..a1f3a82f1037959d665d4cb0fda9c80c28364461 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01830.java @@ -0,0 +1,141 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01830") +public class BenchmarkTest01830 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01830", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/crypto-02/BenchmarkTest01830.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01830")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01831.java b/OWASP DATASET/BenchmarkTest01831.java new file mode 100644 index 0000000000000000000000000000000000000000..e1522266d396f959015507cefe0fba750c50cdae --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01831.java @@ -0,0 +1,132 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest01831") +public class BenchmarkTest01831 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01831", "Ms+Bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/ldapi-00/BenchmarkTest01831.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01831")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + javax.naming.directory.DirContext ctx = ads.getDirContext(); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + bar + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + // System.out.println("Filter " + filter); + boolean found = false; + javax.naming.NamingEnumeration results = + ctx.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01832.java b/OWASP DATASET/BenchmarkTest01832.java new file mode 100644 index 0000000000000000000000000000000000000000..9fc57602d03314a288a21cd9b3b9e0d41d10d7f1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01832.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest01832") +public class BenchmarkTest01832 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01832", "Ms+Bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/ldapi-00/BenchmarkTest01832.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01832")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + javax.naming.directory.DirContext ctx = ads.getDirContext(); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + bar + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + // System.out.println("Filter " + filter); + boolean found = false; + javax.naming.NamingEnumeration results = + ctx.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01833.java b/OWASP DATASET/BenchmarkTest01833.java new file mode 100644 index 0000000000000000000000000000000000000000..5c586b78c68df8591039da0a15de836786eac8c0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01833.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01833") +public class BenchmarkTest01833 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01833", "FileName"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/pathtraver-02/BenchmarkTest01833.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01833")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + java.io.File fileTarget = + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR, bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map9325 = new java.util.HashMap(); + map9325.put("keyA-9325", "a-Value"); // put some stuff in the collection + map9325.put("keyB-9325", param); // put it in a collection + map9325.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map9325.get("keyB-9325"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01834.java b/OWASP DATASET/BenchmarkTest01834.java new file mode 100644 index 0000000000000000000000000000000000000000..8a6f1e4ef9ac846fd121b54eeef6f2ffb5f15370 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01834.java @@ -0,0 +1,111 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01834") +public class BenchmarkTest01834 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01834", "FileName"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/pathtraver-02/BenchmarkTest01834.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01834")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + java.io.File fileTarget = + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR, bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01835.java b/OWASP DATASET/BenchmarkTest01835.java new file mode 100644 index 0000000000000000000000000000000000000000..ee2b8a4c46af123914c689eb3a401b5c250e0101 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01835.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01835") +public class BenchmarkTest01835 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01835", "FileName"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/pathtraver-02/BenchmarkTest01835.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01835")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + java.io.File fileTarget = + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR, bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01836.java b/OWASP DATASET/BenchmarkTest01836.java new file mode 100644 index 0000000000000000000000000000000000000000..6bd242fef47a511fede65a126fe0b72105fca2ce --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01836.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01836") +public class BenchmarkTest01836 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01836", "FileName"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/pathtraver-02/BenchmarkTest01836.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01836")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + // FILE URIs are tricky because they are different between Mac and Windows because of lack + // of standardization. + // Mac requires an extra slash for some reason. + String startURIslashes = ""; + if (System.getProperty("os.name").indexOf("Windows") != -1) + if (System.getProperty("os.name").indexOf("Windows") != -1) startURIslashes = "/"; + else startURIslashes = "//"; + + try { + java.net.URI fileURI = + new java.net.URI( + "file:" + + startURIslashes + + org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + .replace('\\', '/') + .replace(' ', '_') + + bar); + java.io.File fileTarget = new java.io.File(fileURI); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } catch (java.net.URISyntaxException e) { + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map78713 = new java.util.HashMap(); + map78713.put("keyA-78713", "a-Value"); // put some stuff in the collection + map78713.put("keyB-78713", param); // put it in a collection + map78713.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map78713.get("keyB-78713"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01837.java b/OWASP DATASET/BenchmarkTest01837.java new file mode 100644 index 0000000000000000000000000000000000000000..f9f77e51e9847838776de8ad71a66f1e2bcab185 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01837.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01837") +public class BenchmarkTest01837 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01837", "FileName"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/pathtraver-02/BenchmarkTest01837.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01837")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + // FILE URIs are tricky because they are different between Mac and Windows because of lack + // of standardization. + // Mac requires an extra slash for some reason. + String startURIslashes = ""; + if (System.getProperty("os.name").indexOf("Windows") != -1) + if (System.getProperty("os.name").indexOf("Windows") != -1) startURIslashes = "/"; + else startURIslashes = "//"; + + try { + java.net.URI fileURI = + new java.net.URI( + "file", + null, + startURIslashes + + org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + .replace('\\', java.io.File.separatorChar) + .replace(' ', '_') + + bar, + null, + null); + java.io.File fileTarget = new java.io.File(fileURI); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } catch (java.net.URISyntaxException e) { + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01838.java b/OWASP DATASET/BenchmarkTest01838.java new file mode 100644 index 0000000000000000000000000000000000000000..02f4cb14c9899777111f1a3b19b0eb6dac5e7d67 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01838.java @@ -0,0 +1,133 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01838") +public class BenchmarkTest01838 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01838", "FileName"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/pathtraver-02/BenchmarkTest01838.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01838")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(new java.io.File(fileName)); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting FileInputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01839.java b/OWASP DATASET/BenchmarkTest01839.java new file mode 100644 index 0000000000000000000000000000000000000000..5cd170d670a3fe26fa6176a14a3524a177be7ebf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01839.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01839") +public class BenchmarkTest01839 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01839", "FileName"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/pathtraver-02/BenchmarkTest01839.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01839")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName), false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01840.java b/OWASP DATASET/BenchmarkTest01840.java new file mode 100644 index 0000000000000000000000000000000000000000..04533a0c2bd8d72e946d00ebd8aa0057bafd032f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01840.java @@ -0,0 +1,101 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01840") +public class BenchmarkTest01840 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01840", "FileName"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/pathtraver-02/BenchmarkTest01840.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01840")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName)); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01841.java b/OWASP DATASET/BenchmarkTest01841.java new file mode 100644 index 0000000000000000000000000000000000000000..a7f71ab13640ff37123019f0c9d5745418b5b965 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01841.java @@ -0,0 +1,118 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01841") +public class BenchmarkTest01841 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01841", "FileName"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/pathtraver-02/BenchmarkTest01841.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01841")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + try ( + // Create the file first so the test won't throw an exception if it doesn't exist. + // Note: Don't actually do this because this method signature could cause a tool to find + // THIS file constructor + // as a vuln, rather than the File signature we are trying to actually test. + // If necessary, just run the benchmark twice. The 1st run should create all the necessary + // files. + // new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar).createNewFile(); + + java.io.FileOutputStream fos = + new java.io.FileOutputStream(new java.io.FileInputStream(fileName).getFD()); ) { + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a14546 = param; // assign + StringBuilder b14546 = new StringBuilder(a14546); // stick in stringbuilder + b14546.append(" SafeStuff"); // append some safe content + b14546.replace( + b14546.length() - "Chars".length(), + b14546.length(), + "Chars"); // replace some of the end content + java.util.HashMap map14546 = new java.util.HashMap(); + map14546.put("key14546", b14546.toString()); // put in a collection + String c14546 = (String) map14546.get("key14546"); // get it back out + String d14546 = c14546.substring(0, c14546.length() - 1); // extract most of it + String e14546 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d14546.getBytes()))); // B64 encode and decode it + String f14546 = e14546.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g14546 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g14546); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01842.java b/OWASP DATASET/BenchmarkTest01842.java new file mode 100644 index 0000000000000000000000000000000000000000..d1502aaa419365cc111322f21d3b3e23d6187b16 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01842.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01842") +public class BenchmarkTest01842 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01842", "anything"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-04/BenchmarkTest01842.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01842")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + double value = java.lang.Math.random(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Doug"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + response.getWriter().println("Weak Randomness Test java.lang.Math.random() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01843.java b/OWASP DATASET/BenchmarkTest01843.java new file mode 100644 index 0000000000000000000000000000000000000000..63f28da3863f65f61b1e5c77ab5d40af640198a6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01843.java @@ -0,0 +1,134 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01843") +public class BenchmarkTest01843 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01843", "anything"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-04/BenchmarkTest01843.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01843")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + double value = java.lang.Math.random(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Doug"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + response.getWriter().println("Weak Randomness Test java.lang.Math.random() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01844.java b/OWASP DATASET/BenchmarkTest01844.java new file mode 100644 index 0000000000000000000000000000000000000000..8b819ee867f26a8f34c3c7629ebcdcb61310a851 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01844.java @@ -0,0 +1,158 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest01844") +public class BenchmarkTest01844 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01844", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/hash-02/BenchmarkTest01844.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01844")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("SHA1", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a37183 = param; // assign + StringBuilder b37183 = new StringBuilder(a37183); // stick in stringbuilder + b37183.append(" SafeStuff"); // append some safe content + b37183.replace( + b37183.length() - "Chars".length(), + b37183.length(), + "Chars"); // replace some of the end content + java.util.HashMap map37183 = new java.util.HashMap(); + map37183.put("key37183", b37183.toString()); // put in a collection + String c37183 = (String) map37183.get("key37183"); // get it back out + String d37183 = c37183.substring(0, c37183.length() - 1); // extract most of it + String e37183 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d37183.getBytes()))); // B64 encode and decode it + String f37183 = e37183.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g37183 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g37183); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01845.java b/OWASP DATASET/BenchmarkTest01845.java new file mode 100644 index 0000000000000000000000000000000000000000..2578510a3c4833d5de851fc7e9c63691f5f587c0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01845.java @@ -0,0 +1,142 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest01845") +public class BenchmarkTest01845 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01845", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/hash-02/BenchmarkTest01845.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01845")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("SHA1", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01846.java b/OWASP DATASET/BenchmarkTest01846.java new file mode 100644 index 0000000000000000000000000000000000000000..eca48bdbb97321fe68c64044e3187c2839122752 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01846.java @@ -0,0 +1,137 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest01846") +public class BenchmarkTest01846 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01846", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/hash-02/BenchmarkTest01846.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01846")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("SHA1", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01847.java b/OWASP DATASET/BenchmarkTest01847.java new file mode 100644 index 0000000000000000000000000000000000000000..37d64465a21cbcc8569a2f05ace6c5918cf658f4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01847.java @@ -0,0 +1,147 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest01847") +public class BenchmarkTest01847 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01847", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/hash-02/BenchmarkTest01847.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01847")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("sha-384", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("sha-384", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01848.java b/OWASP DATASET/BenchmarkTest01848.java new file mode 100644 index 0000000000000000000000000000000000000000..ad777035c99b8c45c7d47bb3e6c57d86c58c94c6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01848.java @@ -0,0 +1,140 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest01848") +public class BenchmarkTest01848 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01848", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/hash-02/BenchmarkTest01848.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01848")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = + java.security.MessageDigest.getInstance("SHA-512", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01849.java b/OWASP DATASET/BenchmarkTest01849.java new file mode 100644 index 0000000000000000000000000000000000000000..0eb8373036058bf2c874e1e8466fd091bd3e6e70 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01849.java @@ -0,0 +1,151 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest01849") +public class BenchmarkTest01849 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01849", "someSecret"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/hash-02/BenchmarkTest01849.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01849")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = + java.security.MessageDigest.getInstance("SHA-512", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a45344 = param; // assign + StringBuilder b45344 = new StringBuilder(a45344); // stick in stringbuilder + b45344.append(" SafeStuff"); // append some safe content + b45344.replace( + b45344.length() - "Chars".length(), + b45344.length(), + "Chars"); // replace some of the end content + java.util.HashMap map45344 = new java.util.HashMap(); + map45344.put("key45344", b45344.toString()); // put in a collection + String c45344 = (String) map45344.get("key45344"); // get it back out + String d45344 = c45344.substring(0, c45344.length() - 1); // extract most of it + String e45344 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d45344.getBytes()))); // B64 encode and decode it + String f45344 = e45344.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g45344 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g45344); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01850.java b/OWASP DATASET/BenchmarkTest01850.java new file mode 100644 index 0000000000000000000000000000000000000000..b38e94d618ee8f852a29473d4a92f12828ea3f03 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01850.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest01850") +public class BenchmarkTest01850 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01850", "ECHOOO"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/cmdi-02/BenchmarkTest01850.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01850")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01851.java b/OWASP DATASET/BenchmarkTest01851.java new file mode 100644 index 0000000000000000000000000000000000000000..85be124f989be752cea3a4d1210332de45390e16 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01851.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest01851") +public class BenchmarkTest01851 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01851", "ECHOOO"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/cmdi-02/BenchmarkTest01851.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01851")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01852.java b/OWASP DATASET/BenchmarkTest01852.java new file mode 100644 index 0000000000000000000000000000000000000000..6cc163c503d65766a61d5bf897b07195b69f963e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01852.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest01852") +public class BenchmarkTest01852 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01852", "ECHOOO"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/cmdi-02/BenchmarkTest01852.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01852")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + String a1 = ""; + String a2 = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + } else { + a1 = "sh"; + a2 = "-c"; + } + String[] args = {a1, a2, "echo " + bar}; + + ProcessBuilder pb = new ProcessBuilder(args); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.lang.String[]) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01853.java b/OWASP DATASET/BenchmarkTest01853.java new file mode 100644 index 0000000000000000000000000000000000000000..643a9aeddf89c8346b1aa10d43ee6dc07fe00fdc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01853.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01853") +public class BenchmarkTest01853 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01853", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-04/BenchmarkTest01853.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01853")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + byte[] bytes = new byte[10]; + new java.util.Random().nextBytes(bytes); + String rememberMeKey = org.owasp.esapi.ESAPI.encoder().encodeForBase64(bytes, true); + + String user = "Byron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextBytes() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01854.java b/OWASP DATASET/BenchmarkTest01854.java new file mode 100644 index 0000000000000000000000000000000000000000..a1d7a89fe8b0f65d9e321692ad5b8283c2b08a55 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01854.java @@ -0,0 +1,145 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01854") +public class BenchmarkTest01854 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01854", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-04/BenchmarkTest01854.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01854")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + float rand = new java.util.Random().nextFloat(); + String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "Floyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a34242 = param; // assign + StringBuilder b34242 = new StringBuilder(a34242); // stick in stringbuilder + b34242.append(" SafeStuff"); // append some safe content + b34242.replace( + b34242.length() - "Chars".length(), + b34242.length(), + "Chars"); // replace some of the end content + java.util.HashMap map34242 = new java.util.HashMap(); + map34242.put("key34242", b34242.toString()); // put in a collection + String c34242 = (String) map34242.get("key34242"); // get it back out + String d34242 = c34242.substring(0, c34242.length() - 1); // extract most of it + String e34242 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d34242.getBytes()))); // B64 encode and decode it + String f34242 = e34242.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g34242 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g34242); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01855.java b/OWASP DATASET/BenchmarkTest01855.java new file mode 100644 index 0000000000000000000000000000000000000000..d49fd5d4a105e8a6e2113a2b2a471666dd1d21d8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01855.java @@ -0,0 +1,134 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01855") +public class BenchmarkTest01855 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01855", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-04/BenchmarkTest01855.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01855")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01856.java b/OWASP DATASET/BenchmarkTest01856.java new file mode 100644 index 0000000000000000000000000000000000000000..aaf7bbac2ae380dcc03544a32132772e87ebb41e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01856.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01856") +public class BenchmarkTest01856 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01856", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-04/BenchmarkTest01856.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01856")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01857.java b/OWASP DATASET/BenchmarkTest01857.java new file mode 100644 index 0000000000000000000000000000000000000000..8598803d2bbd6f2c9421ee48949bdcdfcfdbcdcd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01857.java @@ -0,0 +1,131 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01857") +public class BenchmarkTest01857 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01857", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-04/BenchmarkTest01857.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01857")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01858.java b/OWASP DATASET/BenchmarkTest01858.java new file mode 100644 index 0000000000000000000000000000000000000000..607a500c9ebfc90d721b17f85fdc2de6e23e1c67 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01858.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01858") +public class BenchmarkTest01858 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01858", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-04/BenchmarkTest01858.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01858")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map95052 = new java.util.HashMap(); + map95052.put("keyA-95052", "a_Value"); // put some stuff in the collection + map95052.put("keyB-95052", param); // put it in a collection + map95052.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map95052.get("keyB-95052"); // get it back out + bar = (String) map95052.get("keyA-95052"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01859.java b/OWASP DATASET/BenchmarkTest01859.java new file mode 100644 index 0000000000000000000000000000000000000000..8567931dd0cdf2975b9cd6363aa8519d114a55e6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01859.java @@ -0,0 +1,125 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01859") +public class BenchmarkTest01859 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01859", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-04/BenchmarkTest01859.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01859")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01860.java b/OWASP DATASET/BenchmarkTest01860.java new file mode 100644 index 0000000000000000000000000000000000000000..85f530e06fecdd85070a7195ca2b566c2eba00ad --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01860.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01860") +public class BenchmarkTest01860 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01860", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-04/BenchmarkTest01860.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01860")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01861.java b/OWASP DATASET/BenchmarkTest01861.java new file mode 100644 index 0000000000000000000000000000000000000000..eed2e87d020246acbc9fd6d1bb7015cba072c864 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01861.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest01861") +public class BenchmarkTest01861 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01861", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/securecookie-00/BenchmarkTest01861.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01861")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01862.java b/OWASP DATASET/BenchmarkTest01862.java new file mode 100644 index 0000000000000000000000000000000000000000..acfe2945bf630f04550cce62e8c2d4476bebf6f3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01862.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest01862") +public class BenchmarkTest01862 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01862", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/securecookie-00/BenchmarkTest01862.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01862")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01863.java b/OWASP DATASET/BenchmarkTest01863.java new file mode 100644 index 0000000000000000000000000000000000000000..2378cbabea281b52f0e3edde565dc43e89d847e0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01863.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest01863") +public class BenchmarkTest01863 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01863", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/securecookie-00/BenchmarkTest01863.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01863")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01864.java b/OWASP DATASET/BenchmarkTest01864.java new file mode 100644 index 0000000000000000000000000000000000000000..28a4a7b34cf9aebfb41694060bf1c57b5c9057fd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01864.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest01864") +public class BenchmarkTest01864 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01864", "ls"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/cmdi-02/BenchmarkTest01864.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01864")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01865.java b/OWASP DATASET/BenchmarkTest01865.java new file mode 100644 index 0000000000000000000000000000000000000000..0da0955c2a51c3b648879ea8568fa9125c2e902f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01865.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest01865") +public class BenchmarkTest01865 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01865", "ls"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/cmdi-02/BenchmarkTest01865.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01865")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01866.java b/OWASP DATASET/BenchmarkTest01866.java new file mode 100644 index 0000000000000000000000000000000000000000..ee1eb6e0b1928795f4dbad50d0c3b53cc62eedb5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01866.java @@ -0,0 +1,139 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01866") +public class BenchmarkTest01866 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01866", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-04/BenchmarkTest01866.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01866")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + double rand = getNextNumber(numGen); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonatella"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + double getNextNumber(java.util.Random generator) { + return generator.nextDouble(); + } + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01867.java b/OWASP DATASET/BenchmarkTest01867.java new file mode 100644 index 0000000000000000000000000000000000000000..e678175587dca3b9d0277176ef7d8d32317caecd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01867.java @@ -0,0 +1,143 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01867") +public class BenchmarkTest01867 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01867", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-04/BenchmarkTest01867.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01867")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + double rand = getNextNumber(numGen); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonatella"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + double getNextNumber(java.util.Random generator) { + return generator.nextDouble(); + } + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map94996 = new java.util.HashMap(); + map94996.put("keyA-94996", "a_Value"); // put some stuff in the collection + map94996.put("keyB-94996", param); // put it in a collection + map94996.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map94996.get("keyB-94996"); // get it back out + bar = (String) map94996.get("keyA-94996"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01868.java b/OWASP DATASET/BenchmarkTest01868.java new file mode 100644 index 0000000000000000000000000000000000000000..8535147c8699c730a1a17f1d304cee53bfa60275 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01868.java @@ -0,0 +1,148 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01868") +public class BenchmarkTest01868 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01868", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-04/BenchmarkTest01868.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01868")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01869.java b/OWASP DATASET/BenchmarkTest01869.java new file mode 100644 index 0000000000000000000000000000000000000000..a0b75ba57515235e20356c86b75cfab12936b384 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01869.java @@ -0,0 +1,138 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01869") +public class BenchmarkTest01869 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01869", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-04/BenchmarkTest01869.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01869")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01870.java b/OWASP DATASET/BenchmarkTest01870.java new file mode 100644 index 0000000000000000000000000000000000000000..323eab57343232179bb67871c3b53f6e532c713f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01870.java @@ -0,0 +1,134 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01870") +public class BenchmarkTest01870 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01870", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-04/BenchmarkTest01870.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01870")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + try { + int r = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "SafeIngrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01871.java b/OWASP DATASET/BenchmarkTest01871.java new file mode 100644 index 0000000000000000000000000000000000000000..acb918ff018eb7b0de0a734a3b05cfba6ad1227b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01871.java @@ -0,0 +1,133 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01871") +public class BenchmarkTest01871 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01871", "whatever"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/weakrand-04/BenchmarkTest01871.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01871")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + try { + int r = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "SafeIngrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz52473 = new StringBuilder(param); + bar = sbxyz52473.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01872.java b/OWASP DATASET/BenchmarkTest01872.java new file mode 100644 index 0000000000000000000000000000000000000000..de4d068f4f1998cff44f94a57265787769ab5134 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01872.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest01872") +public class BenchmarkTest01872 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01872", "color"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/trustbound-01/BenchmarkTest01872.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01872")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String^,java.lang.Object) + request.getSession().putValue(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: 10340 saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01873.java b/OWASP DATASET/BenchmarkTest01873.java new file mode 100644 index 0000000000000000000000000000000000000000..d1fe1addcad9dad09aa5e8fd0f32a9fe2791c1f4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01873.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest01873") +public class BenchmarkTest01873 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01873", "my_user_id"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/trustbound-01/BenchmarkTest01873.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01873")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01874.java b/OWASP DATASET/BenchmarkTest01874.java new file mode 100644 index 0000000000000000000000000000000000000000..1a0f62d4283fa0a13dfdadf4e0058c794f9c5352 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01874.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest01874") +public class BenchmarkTest01874 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01874", "color"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/trustbound-01/BenchmarkTest01874.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01874")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String^,java.lang.Object) + request.getSession().setAttribute(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: '10340' saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01875.java b/OWASP DATASET/BenchmarkTest01875.java new file mode 100644 index 0000000000000000000000000000000000000000..20914fbee14ec34ee2433eadb31eedd87a966f0a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01875.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest01875") +public class BenchmarkTest01875 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01875", "color"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/trustbound-01/BenchmarkTest01875.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01875")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String^,java.lang.Object) + request.getSession().setAttribute(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: '10340' saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01876.java b/OWASP DATASET/BenchmarkTest01876.java new file mode 100644 index 0000000000000000000000000000000000000000..a210e4b6231850f1969f5c5232f62b96eabe4e7f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01876.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest01876") +public class BenchmarkTest01876 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01876", "my_userid"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/trustbound-01/BenchmarkTest01876.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01876")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01877.java b/OWASP DATASET/BenchmarkTest01877.java new file mode 100644 index 0000000000000000000000000000000000000000..8d95fb5adc3135a791c2c583475f517774fcea40 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01877.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01877") +public class BenchmarkTest01877 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie( + "BenchmarkTest01877", "verifyUserPassword%28%27foo%27%2C%27bar%27%29"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-04/BenchmarkTest01877.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01877")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01878.java b/OWASP DATASET/BenchmarkTest01878.java new file mode 100644 index 0000000000000000000000000000000000000000..7b63716dc1851a1a0f961302fdd7f281151a4a83 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01878.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01878") +public class BenchmarkTest01878 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01878", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-04/BenchmarkTest01878.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01878")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01879.java b/OWASP DATASET/BenchmarkTest01879.java new file mode 100644 index 0000000000000000000000000000000000000000..c2d2741ef9ef7f52d9ce9a142937584c9981953a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01879.java @@ -0,0 +1,105 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01879") +public class BenchmarkTest01879 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01879", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-04/BenchmarkTest01879.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01879")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01880.java b/OWASP DATASET/BenchmarkTest01880.java new file mode 100644 index 0000000000000000000000000000000000000000..e646cf220a58c084b3fb33dec6dc127ce9d38912 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01880.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01880") +public class BenchmarkTest01880 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01880", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-04/BenchmarkTest01880.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01880")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map99153 = new java.util.HashMap(); + map99153.put("keyA-99153", "a_Value"); // put some stuff in the collection + map99153.put("keyB-99153", param); // put it in a collection + map99153.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map99153.get("keyB-99153"); // get it back out + bar = (String) map99153.get("keyA-99153"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01881.java b/OWASP DATASET/BenchmarkTest01881.java new file mode 100644 index 0000000000000000000000000000000000000000..6f7c44a9961317b5571c7576fd59288346b0f221 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01881.java @@ -0,0 +1,98 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01881") +public class BenchmarkTest01881 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01881", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-04/BenchmarkTest01881.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01881")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + // System.out.println("no results for query: " + sql + " because the Spring batchUpdate + // method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map20027 = new java.util.HashMap(); + map20027.put("keyA-20027", "a-Value"); // put some stuff in the collection + map20027.put("keyB-20027", param); // put it in a collection + map20027.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map20027.get("keyB-20027"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01882.java b/OWASP DATASET/BenchmarkTest01882.java new file mode 100644 index 0000000000000000000000000000000000000000..2066b1af92e383a093dbd91e6fbf50a4a8db4d25 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01882.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01882") +public class BenchmarkTest01882 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01882", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-04/BenchmarkTest01882.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01882")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.query( + sql, + new org.springframework.jdbc.core.RowMapper() { + @Override + public String mapRow(java.sql.ResultSet rs, int rowNum) + throws java.sql.SQLException { + try { + return rs.getString("USERNAME"); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper + .hideSQLErrors) { + return "Error processing query."; + } else throw e; + } + } + }); + response.getWriter().println("Your results are: "); + + for (String s : results) { + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(s) + "
"); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map67948 = new java.util.HashMap(); + map67948.put("keyA-67948", "a-Value"); // put some stuff in the collection + map67948.put("keyB-67948", param); // put it in a collection + map67948.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map67948.get("keyB-67948"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01883.java b/OWASP DATASET/BenchmarkTest01883.java new file mode 100644 index 0000000000000000000000000000000000000000..855c25e9d443f1996cceeb49097445908201664d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01883.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01883") +public class BenchmarkTest01883 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01883", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-04/BenchmarkTest01883.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01883")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + org.springframework.jdbc.support.rowset.SqlRowSet results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForRowSet(sql); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + while (results.next()) { + response.getWriter() + .println( + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(results.getString("USERNAME")) + + " "); + // System.out.println(results.getString("USERNAME")); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01884.java b/OWASP DATASET/BenchmarkTest01884.java new file mode 100644 index 0000000000000000000000000000000000000000..70f8019f524339610ec41f458040ff1cf4fa1db6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01884.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01884") +public class BenchmarkTest01884 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01884", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-04/BenchmarkTest01884.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01884")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01885.java b/OWASP DATASET/BenchmarkTest01885.java new file mode 100644 index 0000000000000000000000000000000000000000..b36571c9e4a1b9e3f901886016d4f089ca987bcf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01885.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01885") +public class BenchmarkTest01885 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01885", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-04/BenchmarkTest01885.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01885")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01886.java b/OWASP DATASET/BenchmarkTest01886.java new file mode 100644 index 0000000000000000000000000000000000000000..e6b384a110be202c1acac7d6197c4ebbe90c59e7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01886.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01886") +public class BenchmarkTest01886 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01886", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-04/BenchmarkTest01886.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01886")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new String[] {"username", "password"}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a16884 = param; // assign + StringBuilder b16884 = new StringBuilder(a16884); // stick in stringbuilder + b16884.append(" SafeStuff"); // append some safe content + b16884.replace( + b16884.length() - "Chars".length(), + b16884.length(), + "Chars"); // replace some of the end content + java.util.HashMap map16884 = new java.util.HashMap(); + map16884.put("key16884", b16884.toString()); // put in a collection + String c16884 = (String) map16884.get("key16884"); // get it back out + String d16884 = c16884.substring(0, c16884.length() - 1); // extract most of it + String e16884 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d16884.getBytes()))); // B64 encode and decode it + String f16884 = e16884.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g16884 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g16884); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01887.java b/OWASP DATASET/BenchmarkTest01887.java new file mode 100644 index 0000000000000000000000000000000000000000..673748a6804ea40a39e55f142134ea6856dbc5f1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01887.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01887") +public class BenchmarkTest01887 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01887", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-04/BenchmarkTest01887.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01887")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01888.java b/OWASP DATASET/BenchmarkTest01888.java new file mode 100644 index 0000000000000000000000000000000000000000..e671b2c4d54382582e1a5e6bc85f8a0f09ffed0d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01888.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01888") +public class BenchmarkTest01888 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01888", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-04/BenchmarkTest01888.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01888")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01889.java b/OWASP DATASET/BenchmarkTest01889.java new file mode 100644 index 0000000000000000000000000000000000000000..cbea08b093bf7882ba8bc6980c9c906fa6dc1766 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01889.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01889") +public class BenchmarkTest01889 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01889", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-04/BenchmarkTest01889.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01889")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01890.java b/OWASP DATASET/BenchmarkTest01890.java new file mode 100644 index 0000000000000000000000000000000000000000..cf86030798eaab30d68cca96aa0c909f6aac985a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01890.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01890") +public class BenchmarkTest01890 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01890", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-04/BenchmarkTest01890.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01890")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new String[] {"USERNAME", "PASSWORD"}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01891.java b/OWASP DATASET/BenchmarkTest01891.java new file mode 100644 index 0000000000000000000000000000000000000000..c2f0c2122823ec75e71ff4151e5b77feeba368ab --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01891.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01891") +public class BenchmarkTest01891 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01891", "bar"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/sqli-04/BenchmarkTest01891.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01891")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new String[] {"USERNAME", "PASSWORD"}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01892.java b/OWASP DATASET/BenchmarkTest01892.java new file mode 100644 index 0000000000000000000000000000000000000000..63890fb1f2678626c9f86f6b963d2e41cbb3b112 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01892.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest01892") +public class BenchmarkTest01892 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01892", "2222"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/xpathi-00/BenchmarkTest01892.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01892")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + org.w3c.dom.NodeList nodeList = + (org.w3c.dom.NodeList) + xp.compile(expression) + .evaluate(xmlDocument, javax.xml.xpath.XPathConstants.NODESET); + + response.getWriter().println("Your query results are:
"); + + for (int i = 0; i < nodeList.getLength(); i++) { + org.w3c.dom.Element value = (org.w3c.dom.Element) nodeList.item(i); + response.getWriter().println(value.getTextContent() + "
"); + } + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map3451 = new java.util.HashMap(); + map3451.put("keyA-3451", "a-Value"); // put some stuff in the collection + map3451.put("keyB-3451", param); // put it in a collection + map3451.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map3451.get("keyB-3451"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01893.java b/OWASP DATASET/BenchmarkTest01893.java new file mode 100644 index 0000000000000000000000000000000000000000..096f5cf18d41f117cd9fedd398baa4f4cfe66216 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01893.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest01893") +public class BenchmarkTest01893 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01893", "2222"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/xpathi-00/BenchmarkTest01893.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01893")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + org.w3c.dom.NodeList nodeList = + (org.w3c.dom.NodeList) + xp.compile(expression) + .evaluate(xmlDocument, javax.xml.xpath.XPathConstants.NODESET); + + response.getWriter().println("Your query results are:
"); + + for (int i = 0; i < nodeList.getLength(); i++) { + org.w3c.dom.Element value = (org.w3c.dom.Element) nodeList.item(i); + response.getWriter().println(value.getTextContent() + "
"); + } + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01894.java b/OWASP DATASET/BenchmarkTest01894.java new file mode 100644 index 0000000000000000000000000000000000000000..313a19b02e2ef0e95b55dbb9bc5b68d6a57a10a2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01894.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest01894") +public class BenchmarkTest01894 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + javax.servlet.http.Cookie userCookie = + new javax.servlet.http.Cookie("BenchmarkTest01894", "2222"); + userCookie.setMaxAge(60 * 3); // Store cookie for 3 minutes + userCookie.setSecure(true); + userCookie.setPath(request.getRequestURI()); + userCookie.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + response.addCookie(userCookie); + javax.servlet.RequestDispatcher rd = + request.getRequestDispatcher("/xpathi-00/BenchmarkTest01894.html"); + rd.include(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + javax.servlet.http.Cookie[] theCookies = request.getCookies(); + + String param = "noCookieValueSupplied"; + if (theCookies != null) { + for (javax.servlet.http.Cookie theCookie : theCookies) { + if (theCookie.getName().equals("BenchmarkTest01894")) { + param = java.net.URLDecoder.decode(theCookie.getValue(), "UTF-8"); + break; + } + } + } + + String bar = doSomething(request, param); + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + String result = xp.evaluate(expression, xmlDocument); + + response.getWriter().println("Your query results are: " + result + "
"); + + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01895.java b/OWASP DATASET/BenchmarkTest01895.java new file mode 100644 index 0000000000000000000000000000000000000000..99b7e8dcc3863744df4d7d6ee923444fdc317749 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01895.java @@ -0,0 +1,170 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01895") +public class BenchmarkTest01895 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01895") != null) { + param = request.getHeader("BenchmarkTest01895"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01896.java b/OWASP DATASET/BenchmarkTest01896.java new file mode 100644 index 0000000000000000000000000000000000000000..8088a532d000f56535167e214129194ebeb40d8f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01896.java @@ -0,0 +1,128 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01896") +public class BenchmarkTest01896 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01896") != null) { + param = request.getHeader("BenchmarkTest01896"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = org.owasp.benchmark.helpers.Utils.getCipher(); + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01897.java b/OWASP DATASET/BenchmarkTest01897.java new file mode 100644 index 0000000000000000000000000000000000000000..9dbd8b67f81e72dfb63aeacf97c866c72c6cf3fe --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01897.java @@ -0,0 +1,141 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01897") +public class BenchmarkTest01897 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01897") != null) { + param = request.getHeader("BenchmarkTest01897"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01898.java b/OWASP DATASET/BenchmarkTest01898.java new file mode 100644 index 0000000000000000000000000000000000000000..5970ed6658dac19628d354a62d9b95e21eaa89dc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01898.java @@ -0,0 +1,150 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01898") +public class BenchmarkTest01898 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01898") != null) { + param = request.getHeader("BenchmarkTest01898"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01899.java b/OWASP DATASET/BenchmarkTest01899.java new file mode 100644 index 0000000000000000000000000000000000000000..dff3dbf555a3f2e4628e03e16ea5cd664e70428c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01899.java @@ -0,0 +1,125 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01899") +public class BenchmarkTest01899 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01899") != null) { + param = request.getHeader("BenchmarkTest01899"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "AES/CCM/NoPadding", java.security.Security.getProvider("BC")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01900.java b/OWASP DATASET/BenchmarkTest01900.java new file mode 100644 index 0000000000000000000000000000000000000000..4160375312414c52dc55045cd2fb1fb1893dc495 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01900.java @@ -0,0 +1,127 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01900") +public class BenchmarkTest01900 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01900") != null) { + param = request.getHeader("BenchmarkTest01900"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01901.java b/OWASP DATASET/BenchmarkTest01901.java new file mode 100644 index 0000000000000000000000000000000000000000..0fd49d479debd6e5474d0b789dee1db645e2ca73 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01901.java @@ -0,0 +1,133 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01901") +public class BenchmarkTest01901 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01901") != null) { + param = request.getHeader("BenchmarkTest01901"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + // java.security.SecureRandom random = new java.security.SecureRandom(); + // byte[] iv = random.generateSeed(16); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg2", "AES/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz69308 = new StringBuilder(param); + String bar = sbxyz69308.append("_SafeStuff").toString(); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01902.java b/OWASP DATASET/BenchmarkTest01902.java new file mode 100644 index 0000000000000000000000000000000000000000..3544dfadb6e1d01fd18ca10fadeae039d8b389dc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01902.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest01902") +public class BenchmarkTest01902 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01902") != null) { + param = request.getHeader("BenchmarkTest01902"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + javax.naming.directory.DirContext ctx = ads.getDirContext(); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person)(uid=" + bar + "))"; + // System.out.println("Filter " + filter); + boolean found = false; + javax.naming.NamingEnumeration results = + ctx.search(base, filter, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01903.java b/OWASP DATASET/BenchmarkTest01903.java new file mode 100644 index 0000000000000000000000000000000000000000..6a66aa2cba52ae1a6184128fa1f36784acf1fa81 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01903.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest01903") +public class BenchmarkTest01903 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01903") != null) { + param = request.getHeader("BenchmarkTest01903"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + javax.naming.directory.DirContext ctx = ads.getDirContext(); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person)(uid=" + bar + "))"; + // System.out.println("Filter " + filter); + boolean found = false; + javax.naming.NamingEnumeration results = + ctx.search(base, filter, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01904.java b/OWASP DATASET/BenchmarkTest01904.java new file mode 100644 index 0000000000000000000000000000000000000000..6f9397cb21e4437eab6c0079ac0fa2068b3a428c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01904.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01904") +public class BenchmarkTest01904 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01904") != null) { + param = request.getHeader("BenchmarkTest01904"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + java.io.File fileTarget = new java.io.File(bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map13742 = new java.util.HashMap(); + map13742.put("keyA-13742", "a-Value"); // put some stuff in the collection + map13742.put("keyB-13742", param); // put it in a collection + map13742.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map13742.get("keyB-13742"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01905.java b/OWASP DATASET/BenchmarkTest01905.java new file mode 100644 index 0000000000000000000000000000000000000000..d7b30267ee72eeb9465351a3751638213ab392fa --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01905.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01905") +public class BenchmarkTest01905 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01905") != null) { + param = request.getHeader("BenchmarkTest01905"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(fileName); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map33587 = new java.util.HashMap(); + map33587.put("keyA-33587", "a_Value"); // put some stuff in the collection + map33587.put("keyB-33587", param); // put it in a collection + map33587.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map33587.get("keyB-33587"); // get it back out + bar = (String) map33587.get("keyA-33587"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01906.java b/OWASP DATASET/BenchmarkTest01906.java new file mode 100644 index 0000000000000000000000000000000000000000..100a7aa944f45b7c6cad3f0de8325791fe6a2d15 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01906.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01906") +public class BenchmarkTest01906 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01906") != null) { + param = request.getHeader("BenchmarkTest01906"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName)); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01907.java b/OWASP DATASET/BenchmarkTest01907.java new file mode 100644 index 0000000000000000000000000000000000000000..9a3581bb0aa1255e5a6b126263036762b2f57e1e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01907.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01907") +public class BenchmarkTest01907 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01907") != null) { + param = request.getHeader("BenchmarkTest01907"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName)); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01908.java b/OWASP DATASET/BenchmarkTest01908.java new file mode 100644 index 0000000000000000000000000000000000000000..fb1703a709e8c711f2d53e30fdd87af34c5f9de9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01908.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01908") +public class BenchmarkTest01908 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01908") != null) { + param = request.getHeader("BenchmarkTest01908"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + java.io.InputStream is = null; + + try { + java.nio.file.Path path = java.nio.file.Paths.get(fileName); + is = java.nio.file.Files.newInputStream(path, java.nio.file.StandardOpenOption.READ); + byte[] b = new byte[1000]; + int size = is.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + is.close(); + } catch (Exception e) { + System.out.println("Couldn't open InputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting InputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (is != null) { + try { + is.close(); + is = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01909.java b/OWASP DATASET/BenchmarkTest01909.java new file mode 100644 index 0000000000000000000000000000000000000000..f1f0a22c783483786d74d13078c02c5ba8138917 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01909.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest01909") +public class BenchmarkTest01909 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01909") != null) { + param = request.getHeader("BenchmarkTest01909"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person)(uid=" + bar + "))"; + + javax.naming.directory.DirContext ctx = ads.getDirContext(); + javax.naming.directory.InitialDirContext idc = + (javax.naming.directory.InitialDirContext) ctx; + boolean found = false; + javax.naming.NamingEnumeration results = + idc.search(base, filter, sc); + + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map30748 = new java.util.HashMap(); + map30748.put("keyA-30748", "a_Value"); // put some stuff in the collection + map30748.put("keyB-30748", param); // put it in a collection + map30748.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map30748.get("keyB-30748"); // get it back out + bar = (String) map30748.get("keyA-30748"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01910.java b/OWASP DATASET/BenchmarkTest01910.java new file mode 100644 index 0000000000000000000000000000000000000000..cab0943a447f8571f596512a21c4fdbc1908e757 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01910.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01910") +public class BenchmarkTest01910 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01910") != null) { + param = request.getHeader("BenchmarkTest01910"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + double value = java.lang.Math.random(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Doug"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + response.getWriter().println("Weak Randomness Test java.lang.Math.random() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01911.java b/OWASP DATASET/BenchmarkTest01911.java new file mode 100644 index 0000000000000000000000000000000000000000..f5e4a857ebf92a1aa0597be4b11c765eb073a85a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01911.java @@ -0,0 +1,142 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest01911") +public class BenchmarkTest01911 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01911") != null) { + param = request.getHeader("BenchmarkTest01911"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("SHA1", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01912.java b/OWASP DATASET/BenchmarkTest01912.java new file mode 100644 index 0000000000000000000000000000000000000000..87e50b9ed76182ef89021c8dc66add0717bd7a3b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01912.java @@ -0,0 +1,126 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest01912") +public class BenchmarkTest01912 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01912") != null) { + param = request.getHeader("BenchmarkTest01912"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = + java.security.MessageDigest.getInstance("SHA-512", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01913.java b/OWASP DATASET/BenchmarkTest01913.java new file mode 100644 index 0000000000000000000000000000000000000000..d4b62ae6ad27e49908fad4be3ec20391ccf24e32 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01913.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest01913") +public class BenchmarkTest01913 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01913") != null) { + param = request.getHeader("BenchmarkTest01913"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-256"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01914.java b/OWASP DATASET/BenchmarkTest01914.java new file mode 100644 index 0000000000000000000000000000000000000000..9b18cb57a2967652fa8e879fa9a49bdd3142bcb0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01914.java @@ -0,0 +1,73 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01914") +public class BenchmarkTest01914 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + java.io.PrintWriter out = response.getWriter(); + out.write("\n\n\n

"); + out.format(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + out.write("\n

\n\n"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01915.java b/OWASP DATASET/BenchmarkTest01915.java new file mode 100644 index 0000000000000000000000000000000000000000..fbc4d87eeaeabe7c6b618d7cd23328fe3946be47 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01915.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01915") +public class BenchmarkTest01915 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().format("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01916.java b/OWASP DATASET/BenchmarkTest01916.java new file mode 100644 index 0000000000000000000000000000000000000000..666c47ae50a389b92437b66e566796f143e4917a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01916.java @@ -0,0 +1,65 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01916") +public class BenchmarkTest01916 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar.toCharArray()); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01917.java b/OWASP DATASET/BenchmarkTest01917.java new file mode 100644 index 0000000000000000000000000000000000000000..db357e8c3561d75ddb567e4e0c49b35757dcf1f1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01917.java @@ -0,0 +1,64 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01917") +public class BenchmarkTest01917 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01918.java b/OWASP DATASET/BenchmarkTest01918.java new file mode 100644 index 0000000000000000000000000000000000000000..a374d4cf8407f297e8ef79e1ed6d63f839649267 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01918.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01918") +public class BenchmarkTest01918 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01919.java b/OWASP DATASET/BenchmarkTest01919.java new file mode 100644 index 0000000000000000000000000000000000000000..64d4a8caaf7fdda6c079b2ee2ce602904c4d9dff --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01919.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01919") +public class BenchmarkTest01919 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(java.util.Locale.US, bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01920.java b/OWASP DATASET/BenchmarkTest01920.java new file mode 100644 index 0000000000000000000000000000000000000000..8649d0565805efc14ceeff245f6b520b16855b99 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01920.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01920") +public class BenchmarkTest01920 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {bar, "b"}; + response.getWriter().printf("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01921.java b/OWASP DATASET/BenchmarkTest01921.java new file mode 100644 index 0000000000000000000000000000000000000000..55e3148e9be5977f0d7e604a900b669bbddb33ef --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01921.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01921") +public class BenchmarkTest01921 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {bar, "b"}; + response.getWriter().printf("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01922.java b/OWASP DATASET/BenchmarkTest01922.java new file mode 100644 index 0000000000000000000000000000000000000000..e8c5473b89515398a823b8ba6716a1120420d7e4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01922.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01922") +public class BenchmarkTest01922 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01923.java b/OWASP DATASET/BenchmarkTest01923.java new file mode 100644 index 0000000000000000000000000000000000000000..a420911097a390a73c4580135c7fb2158fbb40c4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01923.java @@ -0,0 +1,67 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01923") +public class BenchmarkTest01923 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01924.java b/OWASP DATASET/BenchmarkTest01924.java new file mode 100644 index 0000000000000000000000000000000000000000..38d579a652e1cd52a3a9b0d6e0f35fcc8c8ee925 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01924.java @@ -0,0 +1,65 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01924") +public class BenchmarkTest01924 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01925.java b/OWASP DATASET/BenchmarkTest01925.java new file mode 100644 index 0000000000000000000000000000000000000000..37cf6149abf50e202da5a43ab17e5e212f72cd2f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01925.java @@ -0,0 +1,68 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01925") +public class BenchmarkTest01925 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz28389 = new StringBuilder(param); + bar = sbxyz28389.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01926.java b/OWASP DATASET/BenchmarkTest01926.java new file mode 100644 index 0000000000000000000000000000000000000000..99ea3c819f6b8609a86fdcbf189326d47414254a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01926.java @@ -0,0 +1,69 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01926") +public class BenchmarkTest01926 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01927.java b/OWASP DATASET/BenchmarkTest01927.java new file mode 100644 index 0000000000000000000000000000000000000000..78804f1fd0611901618fd0370b5310c2a3040a45 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01927.java @@ -0,0 +1,71 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest01927") +public class BenchmarkTest01927 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("Referer") != null) { + param = request.getHeader("Referer"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01928.java b/OWASP DATASET/BenchmarkTest01928.java new file mode 100644 index 0000000000000000000000000000000000000000..46fab42eb3b7b8464cbce91658f10268a765bfb4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01928.java @@ -0,0 +1,105 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest01928") +public class BenchmarkTest01928 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01928") != null) { + param = request.getHeader("BenchmarkTest01928"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(); + + pb.command(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01929.java b/OWASP DATASET/BenchmarkTest01929.java new file mode 100644 index 0000000000000000000000000000000000000000..2f57490b5fda685cb4c640a755a33f2fd10462b2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01929.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest01929") +public class BenchmarkTest01929 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01929") != null) { + param = request.getHeader("BenchmarkTest01929"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String a1 = ""; + String a2 = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + } else { + a1 = "sh"; + a2 = "-c"; + } + String[] args = {a1, a2, "echo " + bar}; + + ProcessBuilder pb = new ProcessBuilder(args); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.lang.String[]) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map44 = new java.util.HashMap(); + map44.put("keyA-44", "a-Value"); // put some stuff in the collection + map44.put("keyB-44", param); // put it in a collection + map44.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map44.get("keyB-44"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01930.java b/OWASP DATASET/BenchmarkTest01930.java new file mode 100644 index 0000000000000000000000000000000000000000..dd89857f17346173310847a6a0dc18beea74e29d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01930.java @@ -0,0 +1,111 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01930") +public class BenchmarkTest01930 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01930") != null) { + param = request.getHeader("BenchmarkTest01930"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + double value = new java.util.Random().nextDouble(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Donna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz62502 = new StringBuilder(param); + String bar = sbxyz62502.append("_SafeStuff").toString(); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01931.java b/OWASP DATASET/BenchmarkTest01931.java new file mode 100644 index 0000000000000000000000000000000000000000..80dfb24de3403222e7a030b62084407347cd26e1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01931.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01931") +public class BenchmarkTest01931 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01931") != null) { + param = request.getHeader("BenchmarkTest01931"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + float rand = new java.util.Random().nextFloat(); + String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "Floyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a40465 = param; // assign + StringBuilder b40465 = new StringBuilder(a40465); // stick in stringbuilder + b40465.append(" SafeStuff"); // append some safe content + b40465.replace( + b40465.length() - "Chars".length(), + b40465.length(), + "Chars"); // replace some of the end content + java.util.HashMap map40465 = new java.util.HashMap(); + map40465.put("key40465", b40465.toString()); // put in a collection + String c40465 = (String) map40465.get("key40465"); // get it back out + String d40465 = c40465.substring(0, c40465.length() - 1); // extract most of it + String e40465 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d40465.getBytes()))); // B64 encode and decode it + String f40465 = e40465.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f40465); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01932.java b/OWASP DATASET/BenchmarkTest01932.java new file mode 100644 index 0000000000000000000000000000000000000000..6368db9470c3e5ee8e1dd1c0405fba2ab86af451 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01932.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01932") +public class BenchmarkTest01932 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01932") != null) { + param = request.getHeader("BenchmarkTest01932"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01933.java b/OWASP DATASET/BenchmarkTest01933.java new file mode 100644 index 0000000000000000000000000000000000000000..5e0c0c6dcc1f7bddd844ce72b64dc0ab8bf2afdf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01933.java @@ -0,0 +1,111 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01933") +public class BenchmarkTest01933 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01933") != null) { + param = request.getHeader("BenchmarkTest01933"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01934.java b/OWASP DATASET/BenchmarkTest01934.java new file mode 100644 index 0000000000000000000000000000000000000000..ccadfb109e1df37fcff29c0254b4102453726e1e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01934.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01934") +public class BenchmarkTest01934 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01934") != null) { + param = request.getHeader("BenchmarkTest01934"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01935.java b/OWASP DATASET/BenchmarkTest01935.java new file mode 100644 index 0000000000000000000000000000000000000000..de825221aaeefb9832ae90b50b9f51fadf14a0f2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01935.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest01935") +public class BenchmarkTest01935 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01935") != null) { + param = request.getHeader("BenchmarkTest01935"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a17785 = param; // assign + StringBuilder b17785 = new StringBuilder(a17785); // stick in stringbuilder + b17785.append(" SafeStuff"); // append some safe content + b17785.replace( + b17785.length() - "Chars".length(), + b17785.length(), + "Chars"); // replace some of the end content + java.util.HashMap map17785 = new java.util.HashMap(); + map17785.put("key17785", b17785.toString()); // put in a collection + String c17785 = (String) map17785.get("key17785"); // get it back out + String d17785 = c17785.substring(0, c17785.length() - 1); // extract most of it + String e17785 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d17785.getBytes()))); // B64 encode and decode it + String f17785 = e17785.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f17785); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01936.java b/OWASP DATASET/BenchmarkTest01936.java new file mode 100644 index 0000000000000000000000000000000000000000..227611163ca93c8508adfcc10f72b9c2307ad112 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01936.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest01936") +public class BenchmarkTest01936 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01936") != null) { + param = request.getHeader("BenchmarkTest01936"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01937.java b/OWASP DATASET/BenchmarkTest01937.java new file mode 100644 index 0000000000000000000000000000000000000000..2b49b37b1d53a0c445e36a192ca7c97d5477f766 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01937.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest01937") +public class BenchmarkTest01937 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01937") != null) { + param = request.getHeader("BenchmarkTest01937"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01938.java b/OWASP DATASET/BenchmarkTest01938.java new file mode 100644 index 0000000000000000000000000000000000000000..cdcc7d61715b75d9f3855acfbc8574589d862fb2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01938.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest01938") +public class BenchmarkTest01938 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01938") != null) { + param = request.getHeader("BenchmarkTest01938"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01939.java b/OWASP DATASET/BenchmarkTest01939.java new file mode 100644 index 0000000000000000000000000000000000000000..de7d62663309d3fb9fdaa58ede07b0873ba3eea3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01939.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest01939") +public class BenchmarkTest01939 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01939") != null) { + param = request.getHeader("BenchmarkTest01939"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01940.java b/OWASP DATASET/BenchmarkTest01940.java new file mode 100644 index 0000000000000000000000000000000000000000..aa01245f5ea1e5fc8901f011d7b0fcd4ba1796b8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01940.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest01940") +public class BenchmarkTest01940 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01940") != null) { + param = request.getHeader("BenchmarkTest01940"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01941.java b/OWASP DATASET/BenchmarkTest01941.java new file mode 100644 index 0000000000000000000000000000000000000000..e708e6d43a2c4c656241ae4bcfbbd4e2fc050e7d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01941.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest01941") +public class BenchmarkTest01941 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01941") != null) { + param = request.getHeader("BenchmarkTest01941"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a20426 = param; // assign + StringBuilder b20426 = new StringBuilder(a20426); // stick in stringbuilder + b20426.append(" SafeStuff"); // append some safe content + b20426.replace( + b20426.length() - "Chars".length(), + b20426.length(), + "Chars"); // replace some of the end content + java.util.HashMap map20426 = new java.util.HashMap(); + map20426.put("key20426", b20426.toString()); // put in a collection + String c20426 = (String) map20426.get("key20426"); // get it back out + String d20426 = c20426.substring(0, c20426.length() - 1); // extract most of it + String e20426 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d20426.getBytes()))); // B64 encode and decode it + String f20426 = e20426.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g20426 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g20426); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01942.java b/OWASP DATASET/BenchmarkTest01942.java new file mode 100644 index 0000000000000000000000000000000000000000..5cd095dc65891d21c4f0f796bf882e2e7df4d4b1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01942.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest01942") +public class BenchmarkTest01942 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01942") != null) { + param = request.getHeader("BenchmarkTest01942"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = + r.exec(cmd + bar, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01943.java b/OWASP DATASET/BenchmarkTest01943.java new file mode 100644 index 0000000000000000000000000000000000000000..a8ac3fbbac14942bbab3012da4ed264c79f29833 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01943.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest01943") +public class BenchmarkTest01943 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01943") != null) { + param = request.getHeader("BenchmarkTest01943"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = + r.exec(cmd + bar, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map72345 = new java.util.HashMap(); + map72345.put("keyA-72345", "a_Value"); // put some stuff in the collection + map72345.put("keyB-72345", param); // put it in a collection + map72345.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map72345.get("keyB-72345"); // get it back out + bar = (String) map72345.get("keyA-72345"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01944.java b/OWASP DATASET/BenchmarkTest01944.java new file mode 100644 index 0000000000000000000000000000000000000000..5db746ebc69a6e250d94d6aefa42b73e343d4c23 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01944.java @@ -0,0 +1,100 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest01944") +public class BenchmarkTest01944 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01944") != null) { + param = request.getHeader("BenchmarkTest01944"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = + r.exec(cmd + bar, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01945.java b/OWASP DATASET/BenchmarkTest01945.java new file mode 100644 index 0000000000000000000000000000000000000000..d8c9d557a873dca80177164e49442e52b10e88c2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01945.java @@ -0,0 +1,134 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01945") +public class BenchmarkTest01945 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01945") != null) { + param = request.getHeader("BenchmarkTest01945"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01946.java b/OWASP DATASET/BenchmarkTest01946.java new file mode 100644 index 0000000000000000000000000000000000000000..ef185880a4b7078223b1608621ce35b3f5b083dd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01946.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01946") +public class BenchmarkTest01946 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01946") != null) { + param = request.getHeader("BenchmarkTest01946"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01947.java b/OWASP DATASET/BenchmarkTest01947.java new file mode 100644 index 0000000000000000000000000000000000000000..38579d672a2cb9c4c4d354e6939021cc21636cc3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01947.java @@ -0,0 +1,134 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01947") +public class BenchmarkTest01947 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01947") != null) { + param = request.getHeader("BenchmarkTest01947"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01948.java b/OWASP DATASET/BenchmarkTest01948.java new file mode 100644 index 0000000000000000000000000000000000000000..2c6646a0ed2d31560c3dc491d2f3ebbd948643f5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01948.java @@ -0,0 +1,128 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01948") +public class BenchmarkTest01948 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01948") != null) { + param = request.getHeader("BenchmarkTest01948"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz84277 = new StringBuilder(param); + bar = sbxyz84277.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01949.java b/OWASP DATASET/BenchmarkTest01949.java new file mode 100644 index 0000000000000000000000000000000000000000..af03e941dead1a8bc1e70474645fded85fe233bf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01949.java @@ -0,0 +1,118 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01949") +public class BenchmarkTest01949 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01949") != null) { + param = request.getHeader("BenchmarkTest01949"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01950.java b/OWASP DATASET/BenchmarkTest01950.java new file mode 100644 index 0000000000000000000000000000000000000000..caedaab27d626ca508cf47714239d1dfe64ca5a7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01950.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01950") +public class BenchmarkTest01950 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01950") != null) { + param = request.getHeader("BenchmarkTest01950"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + float rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextFloat(); + String rememberMeKey = + Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeFloyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextFloat() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextFloat() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map14411 = new java.util.HashMap(); + map14411.put("keyA-14411", "a-Value"); // put some stuff in the collection + map14411.put("keyB-14411", param); // put it in a collection + map14411.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map14411.get("keyB-14411"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01951.java b/OWASP DATASET/BenchmarkTest01951.java new file mode 100644 index 0000000000000000000000000000000000000000..255ea8884e410fede2b0f7de9c023665fdfe6571 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01951.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01951") +public class BenchmarkTest01951 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01951") != null) { + param = request.getHeader("BenchmarkTest01951"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + float rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextFloat(); + String rememberMeKey = + Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeFloyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextFloat() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextFloat() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01952.java b/OWASP DATASET/BenchmarkTest01952.java new file mode 100644 index 0000000000000000000000000000000000000000..880b17bdf8f73731a081ee633e85640a8e90249b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01952.java @@ -0,0 +1,126 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01952") +public class BenchmarkTest01952 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01952") != null) { + param = request.getHeader("BenchmarkTest01952"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + double stuff = java.security.SecureRandom.getInstance("SHA1PRNG").nextGaussian(); + String rememberMeKey = + Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "SafeGayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextGaussian() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextGaussian() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01953.java b/OWASP DATASET/BenchmarkTest01953.java new file mode 100644 index 0000000000000000000000000000000000000000..c69dc2f776401711a18c3d7f487538d710934dd6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01953.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01953") +public class BenchmarkTest01953 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01953") != null) { + param = request.getHeader("BenchmarkTest01953"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + long l = java.security.SecureRandom.getInstance("SHA1PRNG").nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "SafeLogan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextLong() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextLong() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01954.java b/OWASP DATASET/BenchmarkTest01954.java new file mode 100644 index 0000000000000000000000000000000000000000..ef95cb7999740731307c34b5e616a859cf64a933 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01954.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01954") +public class BenchmarkTest01954 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01954") != null) { + param = request.getHeader("BenchmarkTest01954"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + long l = java.security.SecureRandom.getInstance("SHA1PRNG").nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "SafeLogan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextLong() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextLong() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01955.java b/OWASP DATASET/BenchmarkTest01955.java new file mode 100644 index 0000000000000000000000000000000000000000..ab7809b741279ada49fc7350b2f476d024d80024 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01955.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest01955") +public class BenchmarkTest01955 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01955") != null) { + param = request.getHeader("BenchmarkTest01955"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String^,java.lang.Object) + request.getSession().putValue(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: 10340 saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01956.java b/OWASP DATASET/BenchmarkTest01956.java new file mode 100644 index 0000000000000000000000000000000000000000..088ea5e2943f7f77818654b68d155208d5c9aafc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01956.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest01956") +public class BenchmarkTest01956 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01956") != null) { + param = request.getHeader("BenchmarkTest01956"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String^,java.lang.Object) + request.getSession().putValue(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: 10340 saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01957.java b/OWASP DATASET/BenchmarkTest01957.java new file mode 100644 index 0000000000000000000000000000000000000000..9af66a89eb2191b93b3f0f59394056bea91398a7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01957.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest01957") +public class BenchmarkTest01957 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01957") != null) { + param = request.getHeader("BenchmarkTest01957"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String^,java.lang.Object) + request.getSession().putValue(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: 10340 saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01958.java b/OWASP DATASET/BenchmarkTest01958.java new file mode 100644 index 0000000000000000000000000000000000000000..295c51eebbd2b0c32ab5c25b58ca7d248013b85d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01958.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest01958") +public class BenchmarkTest01958 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01958") != null) { + param = request.getHeader("BenchmarkTest01958"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz15757 = new StringBuilder(param); + bar = sbxyz15757.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01959.java b/OWASP DATASET/BenchmarkTest01959.java new file mode 100644 index 0000000000000000000000000000000000000000..72462d0bbff0a84a0f7fbe587cf82092b992ed65 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01959.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest01959") +public class BenchmarkTest01959 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01959") != null) { + param = request.getHeader("BenchmarkTest01959"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map4095 = new java.util.HashMap(); + map4095.put("keyA-4095", "a_Value"); // put some stuff in the collection + map4095.put("keyB-4095", param); // put it in a collection + map4095.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map4095.get("keyB-4095"); // get it back out + bar = (String) map4095.get("keyA-4095"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01960.java b/OWASP DATASET/BenchmarkTest01960.java new file mode 100644 index 0000000000000000000000000000000000000000..1141af57303d7f280653132fa9f85c8f26e085e3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01960.java @@ -0,0 +1,73 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest01960") +public class BenchmarkTest01960 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01960") != null) { + param = request.getHeader("BenchmarkTest01960"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01961.java b/OWASP DATASET/BenchmarkTest01961.java new file mode 100644 index 0000000000000000000000000000000000000000..a2b2ca3ddc969f40f08c0ccba2628fd0c9a9c2ac --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01961.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01961") +public class BenchmarkTest01961 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01961") != null) { + param = request.getHeader("BenchmarkTest01961"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a99523 = param; // assign + StringBuilder b99523 = new StringBuilder(a99523); // stick in stringbuilder + b99523.append(" SafeStuff"); // append some safe content + b99523.replace( + b99523.length() - "Chars".length(), + b99523.length(), + "Chars"); // replace some of the end content + java.util.HashMap map99523 = new java.util.HashMap(); + map99523.put("key99523", b99523.toString()); // put in a collection + String c99523 = (String) map99523.get("key99523"); // get it back out + String d99523 = c99523.substring(0, c99523.length() - 1); // extract most of it + String e99523 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d99523.getBytes()))); // B64 encode and decode it + String f99523 = e99523.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g99523 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g99523); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01962.java b/OWASP DATASET/BenchmarkTest01962.java new file mode 100644 index 0000000000000000000000000000000000000000..51a0bbf7de212b461adc038a074e1b67b11cbfb4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01962.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01962") +public class BenchmarkTest01962 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01962") != null) { + param = request.getHeader("BenchmarkTest01962"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, new String[] {"Column1", "Column2"}); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01963.java b/OWASP DATASET/BenchmarkTest01963.java new file mode 100644 index 0000000000000000000000000000000000000000..7eeff79882d60eb0c07e1daf89cf65f1c1c5f7c5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01963.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01963") +public class BenchmarkTest01963 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01963") != null) { + param = request.getHeader("BenchmarkTest01963"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + // System.out.println("no results for query: " + sql + " because the Spring batchUpdate + // method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01964.java b/OWASP DATASET/BenchmarkTest01964.java new file mode 100644 index 0000000000000000000000000000000000000000..3c306c818d490358e7170d8712981200fadc0af3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01964.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01964") +public class BenchmarkTest01964 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01964") != null) { + param = request.getHeader("BenchmarkTest01964"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.query( + sql, + new org.springframework.jdbc.core.RowMapper() { + @Override + public String mapRow(java.sql.ResultSet rs, int rowNum) + throws java.sql.SQLException { + try { + return rs.getString("USERNAME"); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper + .hideSQLErrors) { + return "Error processing query."; + } else throw e; + } + } + }); + response.getWriter().println("Your results are: "); + + for (String s : results) { + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(s) + "
"); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01965.java b/OWASP DATASET/BenchmarkTest01965.java new file mode 100644 index 0000000000000000000000000000000000000000..aaf459b0b0dfe6100c39cbfa2234c689837b4826 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01965.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01965") +public class BenchmarkTest01965 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01965") != null) { + param = request.getHeader("BenchmarkTest01965"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // Long results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForLong(sql); + Long results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Long.class); + response.getWriter().println("Your results are: " + String.valueOf(results)); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01966.java b/OWASP DATASET/BenchmarkTest01966.java new file mode 100644 index 0000000000000000000000000000000000000000..c1c66396b848a0bc897a5a9aec481b6085b688ea --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01966.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01966") +public class BenchmarkTest01966 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01966") != null) { + param = request.getHeader("BenchmarkTest01966"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = + "SELECT TOP 1 USERNAME from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + Object results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, new Object[] {}, String.class); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(results.toString())); + // System.out.println(results.toString()); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01967.java b/OWASP DATASET/BenchmarkTest01967.java new file mode 100644 index 0000000000000000000000000000000000000000..7b820cf2b10b59c3c5ebeacb86726d4dd9fb7f23 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01967.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01967") +public class BenchmarkTest01967 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01967") != null) { + param = request.getHeader("BenchmarkTest01967"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = + "SELECT TOP 1 USERNAME from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + Object results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, new Object[] {}, String.class); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(results.toString())); + // System.out.println(results.toString()); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01968.java b/OWASP DATASET/BenchmarkTest01968.java new file mode 100644 index 0000000000000000000000000000000000000000..f62e19045034390f867fedb4e776e7ae19306757 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01968.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01968") +public class BenchmarkTest01968 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01968") != null) { + param = request.getHeader("BenchmarkTest01968"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01969.java b/OWASP DATASET/BenchmarkTest01969.java new file mode 100644 index 0000000000000000000000000000000000000000..b10477d345fd037621c05c7aa72d23bd8eec1f22 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01969.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01969") +public class BenchmarkTest01969 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01969") != null) { + param = request.getHeader("BenchmarkTest01969"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.addBatch(sql); + int[] counts = statement.executeBatch(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(sql, counts, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01970.java b/OWASP DATASET/BenchmarkTest01970.java new file mode 100644 index 0000000000000000000000000000000000000000..ab775cb53238842f611382a0c5b23fd2e4a2fe2e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01970.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01970") +public class BenchmarkTest01970 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01970") != null) { + param = request.getHeader("BenchmarkTest01970"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.addBatch(sql); + int[] counts = statement.executeBatch(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(sql, counts, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01971.java b/OWASP DATASET/BenchmarkTest01971.java new file mode 100644 index 0000000000000000000000000000000000000000..f964f0481b4c7d9ced3b606bf268c414f41061f3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01971.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01971") +public class BenchmarkTest01971 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01971") != null) { + param = request.getHeader("BenchmarkTest01971"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01972.java b/OWASP DATASET/BenchmarkTest01972.java new file mode 100644 index 0000000000000000000000000000000000000000..e44fec95a16e431fc7943f2e378fc98d954ff8d8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01972.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01972") +public class BenchmarkTest01972 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01972") != null) { + param = request.getHeader("BenchmarkTest01972"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new String[] {"username", "password"}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01973.java b/OWASP DATASET/BenchmarkTest01973.java new file mode 100644 index 0000000000000000000000000000000000000000..4f773d5724fd92f009690d024deabdf0d86f2752 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01973.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest01973") +public class BenchmarkTest01973 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01973") != null) { + param = request.getHeader("BenchmarkTest01973"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01974.java b/OWASP DATASET/BenchmarkTest01974.java new file mode 100644 index 0000000000000000000000000000000000000000..c8da4a6c016898873d26558654543605078cdd25 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01974.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest01974") +public class BenchmarkTest01974 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + if (request.getHeader("BenchmarkTest01974") != null) { + param = request.getHeader("BenchmarkTest01974"); + } + + // URL Decode the header value since req.getHeader() doesn't. Unlike req.getParameter(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + org.w3c.dom.NodeList nodeList = + (org.w3c.dom.NodeList) + xp.compile(expression) + .evaluate(xmlDocument, javax.xml.xpath.XPathConstants.NODESET); + + response.getWriter().println("Your query results are:
"); + + for (int i = 0; i < nodeList.getLength(); i++) { + org.w3c.dom.Element value = (org.w3c.dom.Element) nodeList.item(i); + response.getWriter().println(value.getTextContent() + "
"); + } + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map11821 = new java.util.HashMap(); + map11821.put("keyA-11821", "a-Value"); // put some stuff in the collection + map11821.put("keyB-11821", param); // put it in a collection + map11821.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map11821.get("keyB-11821"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01975.java b/OWASP DATASET/BenchmarkTest01975.java new file mode 100644 index 0000000000000000000000000000000000000000..20a2bdfc985ead5c67e660b6181fd9799201b638 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01975.java @@ -0,0 +1,172 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01975") +public class BenchmarkTest01975 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01976.java b/OWASP DATASET/BenchmarkTest01976.java new file mode 100644 index 0000000000000000000000000000000000000000..768c995b65ede86d80b5652bf528b51e5f50fb4d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01976.java @@ -0,0 +1,173 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01976") +public class BenchmarkTest01976 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz47784 = new StringBuilder(param); + String bar = sbxyz47784.append("_SafeStuff").toString(); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01977.java b/OWASP DATASET/BenchmarkTest01977.java new file mode 100644 index 0000000000000000000000000000000000000000..1b514e109e4f43a9ba9d69e11ecf81b547fcdecb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01977.java @@ -0,0 +1,191 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01977") +public class BenchmarkTest01977 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01978.java b/OWASP DATASET/BenchmarkTest01978.java new file mode 100644 index 0000000000000000000000000000000000000000..60356599ede2ddd1e9c3901454a7866944841922 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01978.java @@ -0,0 +1,145 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01978") +public class BenchmarkTest01978 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz6576 = new StringBuilder(param); + bar = sbxyz6576.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01979.java b/OWASP DATASET/BenchmarkTest01979.java new file mode 100644 index 0000000000000000000000000000000000000000..bf45d44addce6bb3e37e30a259d53b97e0f91dfb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01979.java @@ -0,0 +1,133 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01979") +public class BenchmarkTest01979 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "AES/CCM/NoPadding", java.security.Security.getProvider("BC")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01980.java b/OWASP DATASET/BenchmarkTest01980.java new file mode 100644 index 0000000000000000000000000000000000000000..fd973924983f2315b5cba983f54973eef7c90e59 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01980.java @@ -0,0 +1,133 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01980") +public class BenchmarkTest01980 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz90777 = new StringBuilder(param); + String bar = sbxyz90777.append("_SafeStuff").toString(); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01981.java b/OWASP DATASET/BenchmarkTest01981.java new file mode 100644 index 0000000000000000000000000000000000000000..07a5fae931a04ba6f22117705963fea7ed9c2bf1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01981.java @@ -0,0 +1,137 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01981") +public class BenchmarkTest01981 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01982.java b/OWASP DATASET/BenchmarkTest01982.java new file mode 100644 index 0000000000000000000000000000000000000000..29ba46791619b2794271d76252b8b960928af760 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01982.java @@ -0,0 +1,147 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest01982") +public class BenchmarkTest01982 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + // java.security.SecureRandom random = new java.security.SecureRandom(); + // byte[] iv = random.generateSeed(16); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg2", "AES/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01983.java b/OWASP DATASET/BenchmarkTest01983.java new file mode 100644 index 0000000000000000000000000000000000000000..f3785d5db31aba5f351798d04fa64c4fab8ed41d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01983.java @@ -0,0 +1,93 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01983") +public class BenchmarkTest01983 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + java.io.File fileTarget = + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR, bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01984.java b/OWASP DATASET/BenchmarkTest01984.java new file mode 100644 index 0000000000000000000000000000000000000000..5323f7896a5f4000ccf5b78b41e334ddf2035dab --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01984.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01984") +public class BenchmarkTest01984 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + java.io.File fileTarget = + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR, bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map95438 = new java.util.HashMap(); + map95438.put("keyA-95438", "a_Value"); // put some stuff in the collection + map95438.put("keyB-95438", param); // put it in a collection + map95438.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map95438.get("keyB-95438"); // get it back out + bar = (String) map95438.get("keyA-95438"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01985.java b/OWASP DATASET/BenchmarkTest01985.java new file mode 100644 index 0000000000000000000000000000000000000000..714fb4b6608633773a0f71a8ad4febe7b1d4bed6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01985.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01985") +public class BenchmarkTest01985 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + java.io.File fileTarget = new java.io.File(bar, "/Test.txt"); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01986.java b/OWASP DATASET/BenchmarkTest01986.java new file mode 100644 index 0000000000000000000000000000000000000000..64b33964b723520d494a0202c4cdbf12803be7e4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01986.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01986") +public class BenchmarkTest01986 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + // FILE URIs are tricky because they are different between Mac and Windows because of lack + // of standardization. + // Mac requires an extra slash for some reason. + String startURIslashes = ""; + if (System.getProperty("os.name").indexOf("Windows") != -1) + if (System.getProperty("os.name").indexOf("Windows") != -1) startURIslashes = "/"; + else startURIslashes = "//"; + + try { + java.net.URI fileURI = + new java.net.URI( + "file", + null, + startURIslashes + + org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + .replace('\\', java.io.File.separatorChar) + .replace(' ', '_') + + bar, + null, + null); + java.io.File fileTarget = new java.io.File(fileURI); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } catch (java.net.URISyntaxException e) { + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map83331 = new java.util.HashMap(); + map83331.put("keyA-83331", "a_Value"); // put some stuff in the collection + map83331.put("keyB-83331", param); // put it in a collection + map83331.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map83331.get("keyB-83331"); // get it back out + bar = (String) map83331.get("keyA-83331"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01987.java b/OWASP DATASET/BenchmarkTest01987.java new file mode 100644 index 0000000000000000000000000000000000000000..9235d51000c06de124e9f2d6be69d22be15c6a24 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01987.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01987") +public class BenchmarkTest01987 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + // FILE URIs are tricky because they are different between Mac and Windows because of lack + // of standardization. + // Mac requires an extra slash for some reason. + String startURIslashes = ""; + if (System.getProperty("os.name").indexOf("Windows") != -1) + if (System.getProperty("os.name").indexOf("Windows") != -1) startURIslashes = "/"; + else startURIslashes = "//"; + + try { + java.net.URI fileURI = + new java.net.URI( + "file", + null, + startURIslashes + + org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + .replace('\\', java.io.File.separatorChar) + .replace(' ', '_') + + bar, + null, + null); + java.io.File fileTarget = new java.io.File(fileURI); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } catch (java.net.URISyntaxException e) { + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01988.java b/OWASP DATASET/BenchmarkTest01988.java new file mode 100644 index 0000000000000000000000000000000000000000..9e6ca2e53d255799e1d88076246f6080699dbe24 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01988.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01988") +public class BenchmarkTest01988 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(new java.io.File(fileName)); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting FileInputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01989.java b/OWASP DATASET/BenchmarkTest01989.java new file mode 100644 index 0000000000000000000000000000000000000000..e4bf811cb242ae4e14ee7691b6bd6a2b80867f74 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01989.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01989") +public class BenchmarkTest01989 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName, false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01990.java b/OWASP DATASET/BenchmarkTest01990.java new file mode 100644 index 0000000000000000000000000000000000000000..39b00e56161992ddd9f13adec6b151eda9ed4d51 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01990.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01990") +public class BenchmarkTest01990 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01991.java b/OWASP DATASET/BenchmarkTest01991.java new file mode 100644 index 0000000000000000000000000000000000000000..afb4f0c58e7dff46f96c9ba6e408bb045e569f36 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01991.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest01991") +public class BenchmarkTest01991 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + java.io.InputStream is = null; + + try { + java.nio.file.Path path = java.nio.file.Paths.get(fileName); + is = java.nio.file.Files.newInputStream(path, java.nio.file.StandardOpenOption.READ); + byte[] b = new byte[1000]; + int size = is.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + is.close(); + } catch (Exception e) { + System.out.println("Couldn't open InputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting InputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (is != null) { + try { + is.close(); + is = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a81108 = param; // assign + StringBuilder b81108 = new StringBuilder(a81108); // stick in stringbuilder + b81108.append(" SafeStuff"); // append some safe content + b81108.replace( + b81108.length() - "Chars".length(), + b81108.length(), + "Chars"); // replace some of the end content + java.util.HashMap map81108 = new java.util.HashMap(); + map81108.put("key81108", b81108.toString()); // put in a collection + String c81108 = (String) map81108.get("key81108"); // get it back out + String d81108 = c81108.substring(0, c81108.length() - 1); // extract most of it + String e81108 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d81108.getBytes()))); // B64 encode and decode it + String f81108 = e81108.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g81108 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g81108); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01992.java b/OWASP DATASET/BenchmarkTest01992.java new file mode 100644 index 0000000000000000000000000000000000000000..55d54cb55c04f4373de3aafc8d0f50a54e0bd9bc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01992.java @@ -0,0 +1,140 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01992") +public class BenchmarkTest01992 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + double value = java.lang.Math.random(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Doug"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + response.getWriter().println("Weak Randomness Test java.lang.Math.random() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a82010 = param; // assign + StringBuilder b82010 = new StringBuilder(a82010); // stick in stringbuilder + b82010.append(" SafeStuff"); // append some safe content + b82010.replace( + b82010.length() - "Chars".length(), + b82010.length(), + "Chars"); // replace some of the end content + java.util.HashMap map82010 = new java.util.HashMap(); + map82010.put("key82010", b82010.toString()); // put in a collection + String c82010 = (String) map82010.get("key82010"); // get it back out + String d82010 = c82010.substring(0, c82010.length() - 1); // extract most of it + String e82010 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d82010.getBytes()))); // B64 encode and decode it + String f82010 = e82010.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f82010); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01993.java b/OWASP DATASET/BenchmarkTest01993.java new file mode 100644 index 0000000000000000000000000000000000000000..871a5471f255a8da88da64ff90fe6f936df24177 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01993.java @@ -0,0 +1,140 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest01993") +public class BenchmarkTest01993 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("sha-384", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("sha-384", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01994.java b/OWASP DATASET/BenchmarkTest01994.java new file mode 100644 index 0000000000000000000000000000000000000000..69e82bb6696e65aadb6f9f17cbbebd82c2af068c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01994.java @@ -0,0 +1,135 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest01994") +public class BenchmarkTest01994 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("sha-384", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("sha-384", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01995.java b/OWASP DATASET/BenchmarkTest01995.java new file mode 100644 index 0000000000000000000000000000000000000000..8458c41a799a4b2b3eb850e805eb9920c788e3bb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01995.java @@ -0,0 +1,141 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest01995") +public class BenchmarkTest01995 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-256"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a33633 = param; // assign + StringBuilder b33633 = new StringBuilder(a33633); // stick in stringbuilder + b33633.append(" SafeStuff"); // append some safe content + b33633.replace( + b33633.length() - "Chars".length(), + b33633.length(), + "Chars"); // replace some of the end content + java.util.HashMap map33633 = new java.util.HashMap(); + map33633.put("key33633", b33633.toString()); // put in a collection + String c33633 = (String) map33633.get("key33633"); // get it back out + String d33633 = c33633.substring(0, c33633.length() - 1); // extract most of it + String e33633 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d33633.getBytes()))); // B64 encode and decode it + String f33633 = e33633.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g33633 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g33633); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01996.java b/OWASP DATASET/BenchmarkTest01996.java new file mode 100644 index 0000000000000000000000000000000000000000..a3fc776e7010e05441637be139e23a9ddab2c43e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01996.java @@ -0,0 +1,125 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest01996") +public class BenchmarkTest01996 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01997.java b/OWASP DATASET/BenchmarkTest01997.java new file mode 100644 index 0000000000000000000000000000000000000000..4d7ed738459d07c3ed56243ce3a534f413cdf2f9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01997.java @@ -0,0 +1,127 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest01997") +public class BenchmarkTest01997 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01998.java b/OWASP DATASET/BenchmarkTest01998.java new file mode 100644 index 0000000000000000000000000000000000000000..33a2e722417d07a23186fd3f31ee8f9add8a076d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01998.java @@ -0,0 +1,143 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest01998") +public class BenchmarkTest01998 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest01999.java b/OWASP DATASET/BenchmarkTest01999.java new file mode 100644 index 0000000000000000000000000000000000000000..39b19b3a3925785cc9976c98630884bbaaffad67 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest01999.java @@ -0,0 +1,126 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest01999") +public class BenchmarkTest01999 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + byte[] bytes = new byte[10]; + new java.util.Random().nextBytes(bytes); + String rememberMeKey = org.owasp.esapi.ESAPI.encoder().encodeForBase64(bytes, true); + + String user = "Byron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextBytes() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map28743 = new java.util.HashMap(); + map28743.put("keyA-28743", "a-Value"); // put some stuff in the collection + map28743.put("keyB-28743", param); // put it in a collection + map28743.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map28743.get("keyB-28743"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02000.java b/OWASP DATASET/BenchmarkTest02000.java new file mode 100644 index 0000000000000000000000000000000000000000..0973ea2b893764684f05c62c4383199460586941 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02000.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02000") +public class BenchmarkTest02000 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + byte[] bytes = new byte[10]; + new java.util.Random().nextBytes(bytes); + String rememberMeKey = org.owasp.esapi.ESAPI.encoder().encodeForBase64(bytes, true); + + String user = "Byron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextBytes() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02001.java b/OWASP DATASET/BenchmarkTest02001.java new file mode 100644 index 0000000000000000000000000000000000000000..770047cfc0ce5a661472387fc43e945ec6db264d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02001.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02001") +public class BenchmarkTest02001 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + float rand = new java.util.Random().nextFloat(); + String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "Floyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02002.java b/OWASP DATASET/BenchmarkTest02002.java new file mode 100644 index 0000000000000000000000000000000000000000..11e685c3eb4601541122ba4da386e31053bca09e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02002.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02002") +public class BenchmarkTest02002 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + int randNumber = new java.util.Random().nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "Inga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt(int) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02003.java b/OWASP DATASET/BenchmarkTest02003.java new file mode 100644 index 0000000000000000000000000000000000000000..80796377fa6e98906cc77952f3608783b9125145 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02003.java @@ -0,0 +1,140 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02003") +public class BenchmarkTest02003 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a69278 = param; // assign + StringBuilder b69278 = new StringBuilder(a69278); // stick in stringbuilder + b69278.append(" SafeStuff"); // append some safe content + b69278.replace( + b69278.length() - "Chars".length(), + b69278.length(), + "Chars"); // replace some of the end content + java.util.HashMap map69278 = new java.util.HashMap(); + map69278.put("key69278", b69278.toString()); // put in a collection + String c69278 = (String) map69278.get("key69278"); // get it back out + String d69278 = c69278.substring(0, c69278.length() - 1); // extract most of it + String e69278 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d69278.getBytes()))); // B64 encode and decode it + String f69278 = e69278.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g69278 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g69278); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02004.java b/OWASP DATASET/BenchmarkTest02004.java new file mode 100644 index 0000000000000000000000000000000000000000..1c0c54218a470b913ebd6bdfaa7fc9129eb4b3b0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02004.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02004") +public class BenchmarkTest02004 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02005.java b/OWASP DATASET/BenchmarkTest02005.java new file mode 100644 index 0000000000000000000000000000000000000000..d7dbf68655eee40935eec045c9a9ed9206ddb368 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02005.java @@ -0,0 +1,105 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest02005") +public class BenchmarkTest02005 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map44210 = new java.util.HashMap(); + map44210.put("keyA-44210", "a-Value"); // put some stuff in the collection + map44210.put("keyB-44210", param); // put it in a collection + map44210.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map44210.get("keyB-44210"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02006.java b/OWASP DATASET/BenchmarkTest02006.java new file mode 100644 index 0000000000000000000000000000000000000000..327b4ca683c3aec433189d6f83c7091851ac9c61 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02006.java @@ -0,0 +1,101 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest02006") +public class BenchmarkTest02006 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz44058 = new StringBuilder(param); + String bar = sbxyz44058.append("_SafeStuff").toString(); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02007.java b/OWASP DATASET/BenchmarkTest02007.java new file mode 100644 index 0000000000000000000000000000000000000000..c8f8b611822d9ba037a0a1165e55a6379161ae57 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02007.java @@ -0,0 +1,139 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02007") +public class BenchmarkTest02007 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02008.java b/OWASP DATASET/BenchmarkTest02008.java new file mode 100644 index 0000000000000000000000000000000000000000..d9c6eec1309c924452752068085d07c54f5c422b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02008.java @@ -0,0 +1,158 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02008") +public class BenchmarkTest02008 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + getNextNumber(numGen, randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeBystander"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + void getNextNumber(java.util.Random generator, byte[] barray) { + generator.nextBytes(barray); + } + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a97712 = param; // assign + StringBuilder b97712 = new StringBuilder(a97712); // stick in stringbuilder + b97712.append(" SafeStuff"); // append some safe content + b97712.replace( + b97712.length() - "Chars".length(), + b97712.length(), + "Chars"); // replace some of the end content + java.util.HashMap map97712 = new java.util.HashMap(); + map97712.put("key97712", b97712.toString()); // put in a collection + String c97712 = (String) map97712.get("key97712"); // get it back out + String d97712 = c97712.substring(0, c97712.length() - 1); // extract most of it + String e97712 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d97712.getBytes()))); // B64 encode and decode it + String f97712 = e97712.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g97712 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g97712); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02009.java b/OWASP DATASET/BenchmarkTest02009.java new file mode 100644 index 0000000000000000000000000000000000000000..04593ea5444eb616299e15237b42c991d441a50f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02009.java @@ -0,0 +1,142 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02009") +public class BenchmarkTest02009 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + getNextNumber(numGen, randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeBystander"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + void getNextNumber(java.util.Random generator, byte[] barray) { + generator.nextBytes(barray); + } + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02010.java b/OWASP DATASET/BenchmarkTest02010.java new file mode 100644 index 0000000000000000000000000000000000000000..a4b849788667528c24472032d0a26ff021955cf4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02010.java @@ -0,0 +1,133 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02010") +public class BenchmarkTest02010 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02011.java b/OWASP DATASET/BenchmarkTest02011.java new file mode 100644 index 0000000000000000000000000000000000000000..20abd4c5674e7c6d35a00defe34874117273c31a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02011.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02011") +public class BenchmarkTest02011 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz64726 = new StringBuilder(param); + String bar = sbxyz64726.append("_SafeStuff").toString(); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02012.java b/OWASP DATASET/BenchmarkTest02012.java new file mode 100644 index 0000000000000000000000000000000000000000..a70861186e3cee45bfa84cb8201c348c61598f2c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02012.java @@ -0,0 +1,155 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02012") +public class BenchmarkTest02012 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a69185 = param; // assign + StringBuilder b69185 = new StringBuilder(a69185); // stick in stringbuilder + b69185.append(" SafeStuff"); // append some safe content + b69185.replace( + b69185.length() - "Chars".length(), + b69185.length(), + "Chars"); // replace some of the end content + java.util.HashMap map69185 = new java.util.HashMap(); + map69185.put("key69185", b69185.toString()); // put in a collection + String c69185 = (String) map69185.get("key69185"); // get it back out + String d69185 = c69185.substring(0, c69185.length() - 1); // extract most of it + String e69185 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d69185.getBytes()))); // B64 encode and decode it + String f69185 = e69185.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g69185 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g69185); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02013.java b/OWASP DATASET/BenchmarkTest02013.java new file mode 100644 index 0000000000000000000000000000000000000000..be09f9a6ffa3402a23b1855e216bbc40bfa4efbc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02013.java @@ -0,0 +1,128 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02013") +public class BenchmarkTest02013 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02014.java b/OWASP DATASET/BenchmarkTest02014.java new file mode 100644 index 0000000000000000000000000000000000000000..cdf9e9eca8623e6af8e4cc4506bac36e98dc86e2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02014.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02014") +public class BenchmarkTest02014 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + try { + long l = java.security.SecureRandom.getInstance("SHA1PRNG").nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "SafeLogan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextLong() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextLong() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map37065 = new java.util.HashMap(); + map37065.put("keyA-37065", "a-Value"); // put some stuff in the collection + map37065.put("keyB-37065", param); // put it in a collection + map37065.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map37065.get("keyB-37065"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02015.java b/OWASP DATASET/BenchmarkTest02015.java new file mode 100644 index 0000000000000000000000000000000000000000..32eca8711220a512e44f08c9daaa7c2ea365d8a0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02015.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest02015") +public class BenchmarkTest02015 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String^,java.lang.Object) + request.getSession().putValue(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: 10340 saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02016.java b/OWASP DATASET/BenchmarkTest02016.java new file mode 100644 index 0000000000000000000000000000000000000000..815987e35f3bc2458f3536bb61ee19c58d950041 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02016.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest02016") +public class BenchmarkTest02016 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration names = request.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + + if (org.owasp.benchmark.helpers.Utils.commonHeaders.contains(name)) { + continue; // If standard header, move on to next one + } + + java.util.Enumeration values = request.getHeaders(name); + if (values != null && values.hasMoreElements()) { + param = name; // Grabs the name of the first non-standard header as the parameter + // value + break; + } + } + // Note: We don't URL decode header names because people don't normally do that + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02017.java b/OWASP DATASET/BenchmarkTest02017.java new file mode 100644 index 0000000000000000000000000000000000000000..fd7d463ce47398f7d67ff710e8c29b240d3edc61 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02017.java @@ -0,0 +1,170 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02017") +public class BenchmarkTest02017 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02017"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "DES/CBC/PKCS5PADDING", java.security.Security.getProvider("SunJCE")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02018.java b/OWASP DATASET/BenchmarkTest02018.java new file mode 100644 index 0000000000000000000000000000000000000000..b66c6988ab23cbe134262e1dcaa9fd4f633d24d9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02018.java @@ -0,0 +1,183 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02018") +public class BenchmarkTest02018 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02018"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "DES/CBC/PKCS5PADDING", java.security.Security.getProvider("SunJCE")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a50268 = param; // assign + StringBuilder b50268 = new StringBuilder(a50268); // stick in stringbuilder + b50268.append(" SafeStuff"); // append some safe content + b50268.replace( + b50268.length() - "Chars".length(), + b50268.length(), + "Chars"); // replace some of the end content + java.util.HashMap map50268 = new java.util.HashMap(); + map50268.put("key50268", b50268.toString()); // put in a collection + String c50268 = (String) map50268.get("key50268"); // get it back out + String d50268 = c50268.substring(0, c50268.length() - 1); // extract most of it + String e50268 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d50268.getBytes()))); // B64 encode and decode it + String f50268 = e50268.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f50268); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02019.java b/OWASP DATASET/BenchmarkTest02019.java new file mode 100644 index 0000000000000000000000000000000000000000..feef3edd28a4fbc0b75ab2777f60c4a096819df7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02019.java @@ -0,0 +1,166 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02019") +public class BenchmarkTest02019 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02019"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "DES/CBC/PKCS5PADDING", java.security.Security.getProvider("SunJCE")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02020.java b/OWASP DATASET/BenchmarkTest02020.java new file mode 100644 index 0000000000000000000000000000000000000000..9e09cd7b37190a1aa560cd4e63bc6fdc97731933 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02020.java @@ -0,0 +1,173 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02020") +public class BenchmarkTest02020 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02020"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map95233 = new java.util.HashMap(); + map95233.put("keyA-95233", "a_Value"); // put some stuff in the collection + map95233.put("keyB-95233", param); // put it in a collection + map95233.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map95233.get("keyB-95233"); // get it back out + bar = (String) map95233.get("keyA-95233"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02021.java b/OWASP DATASET/BenchmarkTest02021.java new file mode 100644 index 0000000000000000000000000000000000000000..5a945c0265c419840370f45284319f7771d50614 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02021.java @@ -0,0 +1,135 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02021") +public class BenchmarkTest02021 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02021"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "AES/CCM/NoPadding", java.security.Security.getProvider("BC")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02022.java b/OWASP DATASET/BenchmarkTest02022.java new file mode 100644 index 0000000000000000000000000000000000000000..1b7491385dec0fafe5f368fcc62681ee9a615e06 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02022.java @@ -0,0 +1,127 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02022") +public class BenchmarkTest02022 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02022"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02023.java b/OWASP DATASET/BenchmarkTest02023.java new file mode 100644 index 0000000000000000000000000000000000000000..36a20ac1c82968e93cf575299df90279592db312 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02023.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02023") +public class BenchmarkTest02023 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02023"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02024.java b/OWASP DATASET/BenchmarkTest02024.java new file mode 100644 index 0000000000000000000000000000000000000000..5da961946022ef6dad21d0ca4e20eb2e01912175 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02024.java @@ -0,0 +1,135 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02024") +public class BenchmarkTest02024 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02024"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + // java.security.SecureRandom random = new java.security.SecureRandom(); + // byte[] iv = random.generateSeed(16); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg2", "AES/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02025.java b/OWASP DATASET/BenchmarkTest02025.java new file mode 100644 index 0000000000000000000000000000000000000000..1110a48f83a1d341a0d763c4804998d6d41398ce --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02025.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest02025") +public class BenchmarkTest02025 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02025"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + javax.naming.directory.DirContext ctx = ads.getDirContext(); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person)(uid=" + bar + "))"; + // System.out.println("Filter " + filter); + boolean found = false; + javax.naming.NamingEnumeration results = + ctx.search(base, filter, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02026.java b/OWASP DATASET/BenchmarkTest02026.java new file mode 100644 index 0000000000000000000000000000000000000000..ea8e44c248551f48b001efd4b4483da9e0fe2777 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02026.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02026") +public class BenchmarkTest02026 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02026"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02027.java b/OWASP DATASET/BenchmarkTest02027.java new file mode 100644 index 0000000000000000000000000000000000000000..a3aafdaf5fddf5d2b364698c78347081b417ba23 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02027.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02027") +public class BenchmarkTest02027 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02027"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + java.io.File fileTarget = + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR, bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02028.java b/OWASP DATASET/BenchmarkTest02028.java new file mode 100644 index 0000000000000000000000000000000000000000..76b4d8489111aa8329bcc884bb6434c30107264e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02028.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02028") +public class BenchmarkTest02028 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02028"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + java.io.File fileTarget = + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR, bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02029.java b/OWASP DATASET/BenchmarkTest02029.java new file mode 100644 index 0000000000000000000000000000000000000000..7102992c516d8a51742a1224e1fce3cb9c809c81 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02029.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02029") +public class BenchmarkTest02029 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02029"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + java.io.File fileTarget = new java.io.File(bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map96688 = new java.util.HashMap(); + map96688.put("keyA-96688", "a_Value"); // put some stuff in the collection + map96688.put("keyB-96688", param); // put it in a collection + map96688.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map96688.get("keyB-96688"); // get it back out + bar = (String) map96688.get("keyA-96688"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02030.java b/OWASP DATASET/BenchmarkTest02030.java new file mode 100644 index 0000000000000000000000000000000000000000..0afe770576ddd050f1dfa395f46faf17982ac5bc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02030.java @@ -0,0 +1,123 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02030") +public class BenchmarkTest02030 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02030"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // FILE URIs are tricky because they are different between Mac and Windows because of lack + // of standardization. + // Mac requires an extra slash for some reason. + String startURIslashes = ""; + if (System.getProperty("os.name").indexOf("Windows") != -1) + if (System.getProperty("os.name").indexOf("Windows") != -1) startURIslashes = "/"; + else startURIslashes = "//"; + + try { + java.net.URI fileURI = + new java.net.URI( + "file", + null, + startURIslashes + + org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + .replace('\\', java.io.File.separatorChar) + .replace(' ', '_') + + bar, + null, + null); + java.io.File fileTarget = new java.io.File(fileURI); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } catch (java.net.URISyntaxException e) { + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a60868 = param; // assign + StringBuilder b60868 = new StringBuilder(a60868); // stick in stringbuilder + b60868.append(" SafeStuff"); // append some safe content + b60868.replace( + b60868.length() - "Chars".length(), + b60868.length(), + "Chars"); // replace some of the end content + java.util.HashMap map60868 = new java.util.HashMap(); + map60868.put("key60868", b60868.toString()); // put in a collection + String c60868 = (String) map60868.get("key60868"); // get it back out + String d60868 = c60868.substring(0, c60868.length() - 1); // extract most of it + String e60868 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d60868.getBytes()))); // B64 encode and decode it + String f60868 = e60868.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g60868 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g60868); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02031.java b/OWASP DATASET/BenchmarkTest02031.java new file mode 100644 index 0000000000000000000000000000000000000000..ec32bf9adc598f7f680fd7f36f6c261f0ba62184 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02031.java @@ -0,0 +1,107 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02031") +public class BenchmarkTest02031 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02031"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(new java.io.File(fileName)); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting FileInputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02032.java b/OWASP DATASET/BenchmarkTest02032.java new file mode 100644 index 0000000000000000000000000000000000000000..50d0c07a14621064156d5ee62998862345861b18 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02032.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02032") +public class BenchmarkTest02032 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02032"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(fileName); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02033.java b/OWASP DATASET/BenchmarkTest02033.java new file mode 100644 index 0000000000000000000000000000000000000000..50b7b2824b8b56a1cd8b8be6180b047627221efe --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02033.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02033") +public class BenchmarkTest02033 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02033"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName), false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02034.java b/OWASP DATASET/BenchmarkTest02034.java new file mode 100644 index 0000000000000000000000000000000000000000..5b369077dd03c33cca0306843e3aa92b526fe271 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02034.java @@ -0,0 +1,90 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02034") +public class BenchmarkTest02034 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02034"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + try ( + // Create the file first so the test won't throw an exception if it doesn't exist. + // Note: Don't actually do this because this method signature could cause a tool to find + // THIS file constructor + // as a vuln, rather than the File signature we are trying to actually test. + // If necessary, just run the benchmark twice. The 1st run should create all the necessary + // files. + // new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar).createNewFile(); + + java.io.FileOutputStream fos = + new java.io.FileOutputStream(new java.io.FileInputStream(fileName).getFD()); ) { + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02035.java b/OWASP DATASET/BenchmarkTest02035.java new file mode 100644 index 0000000000000000000000000000000000000000..2c8c5fd3416a752968d1d45055b31ebb0bd7e235 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02035.java @@ -0,0 +1,105 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02035") +public class BenchmarkTest02035 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02035"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + java.io.InputStream is = null; + + try { + java.nio.file.Path path = java.nio.file.Paths.get(fileName); + is = java.nio.file.Files.newInputStream(path, java.nio.file.StandardOpenOption.READ); + byte[] b = new byte[1000]; + int size = is.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + is.close(); + } catch (Exception e) { + System.out.println("Couldn't open InputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting InputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (is != null) { + try { + is.close(); + is = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02036.java b/OWASP DATASET/BenchmarkTest02036.java new file mode 100644 index 0000000000000000000000000000000000000000..5e33aaf50208d44ebb78332d862149d08b396d49 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02036.java @@ -0,0 +1,125 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest02036") +public class BenchmarkTest02036 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02036"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + bar + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + + javax.naming.directory.DirContext ctx = ads.getDirContext(); + javax.naming.directory.InitialDirContext idc = + (javax.naming.directory.InitialDirContext) ctx; + boolean found = false; + javax.naming.NamingEnumeration results = + idc.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02037.java b/OWASP DATASET/BenchmarkTest02037.java new file mode 100644 index 0000000000000000000000000000000000000000..3c00fbeb7e823bc133b5c4348b73eae338ad2c19 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02037.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest02037") +public class BenchmarkTest02037 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02037"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + bar + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + + javax.naming.directory.DirContext ctx = ads.getDirContext(); + javax.naming.directory.InitialDirContext idc = + (javax.naming.directory.InitialDirContext) ctx; + boolean found = false; + javax.naming.NamingEnumeration results = + idc.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02038.java b/OWASP DATASET/BenchmarkTest02038.java new file mode 100644 index 0000000000000000000000000000000000000000..052bf2d6054442d6b56f0785e72f28a0bf5da082 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02038.java @@ -0,0 +1,122 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02038") +public class BenchmarkTest02038 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02038"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + double value = java.lang.Math.random(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Doug"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + response.getWriter().println("Weak Randomness Test java.lang.Math.random() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02039.java b/OWASP DATASET/BenchmarkTest02039.java new file mode 100644 index 0000000000000000000000000000000000000000..f30c4842e8ee5c13462f593a035923ecb3211911 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02039.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02039") +public class BenchmarkTest02039 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02039"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + double value = java.lang.Math.random(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Doug"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + response.getWriter().println("Weak Randomness Test java.lang.Math.random() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02040.java b/OWASP DATASET/BenchmarkTest02040.java new file mode 100644 index 0000000000000000000000000000000000000000..2b142b424598156aa39442872b8cbf113ee233aa --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02040.java @@ -0,0 +1,131 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02040") +public class BenchmarkTest02040 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02040"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + double value = java.lang.Math.random(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Doug"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + response.getWriter().println("Weak Randomness Test java.lang.Math.random() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02041.java b/OWASP DATASET/BenchmarkTest02041.java new file mode 100644 index 0000000000000000000000000000000000000000..090fbfabc9619696a26ac3a2a3d61d792aa8e50f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02041.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02041") +public class BenchmarkTest02041 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02041"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("sha-384", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("sha-384", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02042.java b/OWASP DATASET/BenchmarkTest02042.java new file mode 100644 index 0000000000000000000000000000000000000000..a3fcb28620668afdee12f1b0a586a25f9e075a35 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02042.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02042") +public class BenchmarkTest02042 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02042"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02043.java b/OWASP DATASET/BenchmarkTest02043.java new file mode 100644 index 0000000000000000000000000000000000000000..041f71d06ffc752a44272d8af8909659e48b7c8c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02043.java @@ -0,0 +1,122 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02043") +public class BenchmarkTest02043 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02043"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map52182 = new java.util.HashMap(); + map52182.put("keyA-52182", "a_Value"); // put some stuff in the collection + map52182.put("keyB-52182", param); // put it in a collection + map52182.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map52182.get("keyB-52182"); // get it back out + bar = (String) map52182.get("keyA-52182"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02044.java b/OWASP DATASET/BenchmarkTest02044.java new file mode 100644 index 0000000000000000000000000000000000000000..1837aa45e3f9e0e7121b207d3487bf0db7e03a26 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02044.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02044") +public class BenchmarkTest02044 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02044"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz15026 = new StringBuilder(param); + String bar = sbxyz15026.append("_SafeStuff").toString(); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02045.java b/OWASP DATASET/BenchmarkTest02045.java new file mode 100644 index 0000000000000000000000000000000000000000..4d6a5e7bc7d2182bad13782d5e168e67bd9ecac4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02045.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest02045") +public class BenchmarkTest02045 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + java.io.PrintWriter out = response.getWriter(); + out.write("\n\n\n

"); + out.format(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + out.write("\n

\n\n"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02046.java b/OWASP DATASET/BenchmarkTest02046.java new file mode 100644 index 0000000000000000000000000000000000000000..69e7203fe4f9bcc10fa182c17517490009de1197 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02046.java @@ -0,0 +1,71 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest02046") +public class BenchmarkTest02046 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar.toCharArray()); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map81510 = new java.util.HashMap(); + map81510.put("keyA-81510", "a-Value"); // put some stuff in the collection + map81510.put("keyB-81510", param); // put it in a collection + map81510.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map81510.get("keyB-81510"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02047.java b/OWASP DATASET/BenchmarkTest02047.java new file mode 100644 index 0000000000000000000000000000000000000000..9b57ae1c385feab65e4caeef30d8bb6fcbb79c3b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02047.java @@ -0,0 +1,71 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest02047") +public class BenchmarkTest02047 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar.toCharArray()); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02048.java b/OWASP DATASET/BenchmarkTest02048.java new file mode 100644 index 0000000000000000000000000000000000000000..00bc78279c091ceec37c6bf48180ca33a4c8d264 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02048.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest02048") +public class BenchmarkTest02048 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a96053 = param; // assign + StringBuilder b96053 = new StringBuilder(a96053); // stick in stringbuilder + b96053.append(" SafeStuff"); // append some safe content + b96053.replace( + b96053.length() - "Chars".length(), + b96053.length(), + "Chars"); // replace some of the end content + java.util.HashMap map96053 = new java.util.HashMap(); + map96053.put("key96053", b96053.toString()); // put in a collection + String c96053 = (String) map96053.get("key96053"); // get it back out + String d96053 = c96053.substring(0, c96053.length() - 1); // extract most of it + String e96053 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d96053.getBytes()))); // B64 encode and decode it + String f96053 = e96053.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g96053 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g96053); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02049.java b/OWASP DATASET/BenchmarkTest02049.java new file mode 100644 index 0000000000000000000000000000000000000000..44e88c2297ca4b6c32cc6b241f70f0318abdf603 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02049.java @@ -0,0 +1,67 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest02049") +public class BenchmarkTest02049 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02050.java b/OWASP DATASET/BenchmarkTest02050.java new file mode 100644 index 0000000000000000000000000000000000000000..a03ae1457fe62ebe155eb4c96963c8f01a7e5705 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02050.java @@ -0,0 +1,72 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest02050") +public class BenchmarkTest02050 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02051.java b/OWASP DATASET/BenchmarkTest02051.java new file mode 100644 index 0000000000000000000000000000000000000000..ce59c69fb8a075302d2c3e89023d2bd47b0268e8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02051.java @@ -0,0 +1,72 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest02051") +public class BenchmarkTest02051 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {bar, "b"}; + response.getWriter().printf("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02052.java b/OWASP DATASET/BenchmarkTest02052.java new file mode 100644 index 0000000000000000000000000000000000000000..7bb46dd3f0ff0b70dc53c7a1b118c8f103a3242a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02052.java @@ -0,0 +1,73 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest02052") +public class BenchmarkTest02052 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {bar, "b"}; + response.getWriter().printf("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map20081 = new java.util.HashMap(); + map20081.put("keyA-20081", "a_Value"); // put some stuff in the collection + map20081.put("keyB-20081", param); // put it in a collection + map20081.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map20081.get("keyB-20081"); // get it back out + bar = (String) map20081.get("keyA-20081"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02053.java b/OWASP DATASET/BenchmarkTest02053.java new file mode 100644 index 0000000000000000000000000000000000000000..a8e339f5f2511fd39bd4f519500d5fd8aa3c54fd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02053.java @@ -0,0 +1,72 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest02053") +public class BenchmarkTest02053 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {bar, "b"}; + response.getWriter().printf("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02054.java b/OWASP DATASET/BenchmarkTest02054.java new file mode 100644 index 0000000000000000000000000000000000000000..6576dc87c4d982be749c0c5f7bb7a2f8a1acd69c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02054.java @@ -0,0 +1,68 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest02054") +public class BenchmarkTest02054 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02055.java b/OWASP DATASET/BenchmarkTest02055.java new file mode 100644 index 0000000000000000000000000000000000000000..d563e244c467f9d914d23da8c7218a5e50209016 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02055.java @@ -0,0 +1,68 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest02055") +public class BenchmarkTest02055 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar.toCharArray()); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02056.java b/OWASP DATASET/BenchmarkTest02056.java new file mode 100644 index 0000000000000000000000000000000000000000..1ab758ad361761360b3074af55dfaad374539214 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02056.java @@ -0,0 +1,71 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest02056") +public class BenchmarkTest02056 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map88820 = new java.util.HashMap(); + map88820.put("keyA-88820", "a-Value"); // put some stuff in the collection + map88820.put("keyB-88820", param); // put it in a collection + map88820.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map88820.get("keyB-88820"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02057.java b/OWASP DATASET/BenchmarkTest02057.java new file mode 100644 index 0000000000000000000000000000000000000000..58db78e1cb9f48889dc57d97a2ef10f653e6e4d2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02057.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest02057") +public class BenchmarkTest02057 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("Referer"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar, 0, length); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02058.java b/OWASP DATASET/BenchmarkTest02058.java new file mode 100644 index 0000000000000000000000000000000000000000..81169ca12f51a5e1adcc93088508185de26a0a7e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02058.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02058") +public class BenchmarkTest02058 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02058"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02059.java b/OWASP DATASET/BenchmarkTest02059.java new file mode 100644 index 0000000000000000000000000000000000000000..696bac4cbe1093c9d595999b699f1c28b79ab711 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02059.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02059") +public class BenchmarkTest02059 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02059"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String a1 = ""; + String a2 = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + } else { + a1 = "sh"; + a2 = "-c"; + } + String[] args = {a1, a2, "echo " + bar}; + + ProcessBuilder pb = new ProcessBuilder(args); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.lang.String[]) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map36421 = new java.util.HashMap(); + map36421.put("keyA-36421", "a-Value"); // put some stuff in the collection + map36421.put("keyB-36421", param); // put it in a collection + map36421.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map36421.get("keyB-36421"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02060.java b/OWASP DATASET/BenchmarkTest02060.java new file mode 100644 index 0000000000000000000000000000000000000000..e567eae20c4393fef16d27b3fba30a1c6a63ee59 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02060.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02060") +public class BenchmarkTest02060 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02060"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + double value = new java.util.Random().nextDouble(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Donna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02061.java b/OWASP DATASET/BenchmarkTest02061.java new file mode 100644 index 0000000000000000000000000000000000000000..55195bd15b6e8d25ae9996030d6320664c3d50d1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02061.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02061") +public class BenchmarkTest02061 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02061"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02062.java b/OWASP DATASET/BenchmarkTest02062.java new file mode 100644 index 0000000000000000000000000000000000000000..67aa47d36d8bab23ee6ec125524f54cbf3c84b43 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02062.java @@ -0,0 +1,132 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02062") +public class BenchmarkTest02062 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02062"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a60435 = param; // assign + StringBuilder b60435 = new StringBuilder(a60435); // stick in stringbuilder + b60435.append(" SafeStuff"); // append some safe content + b60435.replace( + b60435.length() - "Chars".length(), + b60435.length(), + "Chars"); // replace some of the end content + java.util.HashMap map60435 = new java.util.HashMap(); + map60435.put("key60435", b60435.toString()); // put in a collection + String c60435 = (String) map60435.get("key60435"); // get it back out + String d60435 = c60435.substring(0, c60435.length() - 1); // extract most of it + String e60435 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d60435.getBytes()))); // B64 encode and decode it + String f60435 = e60435.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g60435 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g60435); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02063.java b/OWASP DATASET/BenchmarkTest02063.java new file mode 100644 index 0000000000000000000000000000000000000000..46788324f03812c2176c43f74cc13fd0763865fd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02063.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02063") +public class BenchmarkTest02063 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02063"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02064.java b/OWASP DATASET/BenchmarkTest02064.java new file mode 100644 index 0000000000000000000000000000000000000000..9e0ea7d5fbc8003482c825cc2720ba3e427891b7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02064.java @@ -0,0 +1,98 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest02064") +public class BenchmarkTest02064 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02064"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map96496 = new java.util.HashMap(); + map96496.put("keyA-96496", "a_Value"); // put some stuff in the collection + map96496.put("keyB-96496", param); // put it in a collection + map96496.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map96496.get("keyB-96496"); // get it back out + bar = (String) map96496.get("keyA-96496"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02065.java b/OWASP DATASET/BenchmarkTest02065.java new file mode 100644 index 0000000000000000000000000000000000000000..cfbd19a660efd1e1756ddef1c0f5fb1e19234924 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02065.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest02065") +public class BenchmarkTest02065 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02065"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02066.java b/OWASP DATASET/BenchmarkTest02066.java new file mode 100644 index 0000000000000000000000000000000000000000..6d8b1521172bbc052a11e57c8e62b33bc06b6642 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02066.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest02066") +public class BenchmarkTest02066 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02066"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02067.java b/OWASP DATASET/BenchmarkTest02067.java new file mode 100644 index 0000000000000000000000000000000000000000..a72d1eb562ea3d39a77aedd6437570020aa18382 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02067.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02067") +public class BenchmarkTest02067 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02067"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02068.java b/OWASP DATASET/BenchmarkTest02068.java new file mode 100644 index 0000000000000000000000000000000000000000..3316ddac8cf33078afe7dc0aede1a4405b4b721f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02068.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02068") +public class BenchmarkTest02068 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02068"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02069.java b/OWASP DATASET/BenchmarkTest02069.java new file mode 100644 index 0000000000000000000000000000000000000000..8a03e70ab3358cb3271c03fb392559dc2316bcc2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02069.java @@ -0,0 +1,101 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02069") +public class BenchmarkTest02069 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02069"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02070.java b/OWASP DATASET/BenchmarkTest02070.java new file mode 100644 index 0000000000000000000000000000000000000000..94005f784404103d5c991904ec2af455ea997358 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02070.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02070") +public class BenchmarkTest02070 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02070"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + try { + Process p = r.exec(cmd, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02071.java b/OWASP DATASET/BenchmarkTest02071.java new file mode 100644 index 0000000000000000000000000000000000000000..0b68acc2c79bb9cd23ec04ff12cc04337927d05f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02071.java @@ -0,0 +1,131 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02071") +public class BenchmarkTest02071 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02071"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map68280 = new java.util.HashMap(); + map68280.put("keyA-68280", "a-Value"); // put some stuff in the collection + map68280.put("keyB-68280", param); // put it in a collection + map68280.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map68280.get("keyB-68280"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02072.java b/OWASP DATASET/BenchmarkTest02072.java new file mode 100644 index 0000000000000000000000000000000000000000..6d9605901fea32715324823929ccb07be541b577 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02072.java @@ -0,0 +1,127 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02072") +public class BenchmarkTest02072 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02072"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02073.java b/OWASP DATASET/BenchmarkTest02073.java new file mode 100644 index 0000000000000000000000000000000000000000..297b6e3b87579a358c92945849bec3832aa1f4a9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02073.java @@ -0,0 +1,148 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02073") +public class BenchmarkTest02073 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02073"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + getNextNumber(numGen, randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeBystander"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + void getNextNumber(java.util.Random generator, byte[] barray) { + generator.nextBytes(barray); + } + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02074.java b/OWASP DATASET/BenchmarkTest02074.java new file mode 100644 index 0000000000000000000000000000000000000000..e2fe5a3e0dd00ae71aeec50816909f9157b4e92c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02074.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02074") +public class BenchmarkTest02074 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02074"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz8662 = new StringBuilder(param); + String bar = sbxyz8662.append("_SafeStuff").toString(); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02075.java b/OWASP DATASET/BenchmarkTest02075.java new file mode 100644 index 0000000000000000000000000000000000000000..c46658af8c4fc905f4494e3a51ebfcccd844d24e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02075.java @@ -0,0 +1,132 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02075") +public class BenchmarkTest02075 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02075"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + double rand = getNextNumber(numGen); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonatella"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + double getNextNumber(java.util.Random generator) { + return generator.nextDouble(); + } + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02076.java b/OWASP DATASET/BenchmarkTest02076.java new file mode 100644 index 0000000000000000000000000000000000000000..ab90fd7698b1a2a3e1ea5b035623b44a899ce09f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02076.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02076") +public class BenchmarkTest02076 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02076"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + double rand = getNextNumber(numGen); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonatella"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + double getNextNumber(java.util.Random generator) { + return generator.nextDouble(); + } + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map15760 = new java.util.HashMap(); + map15760.put("keyA-15760", "a-Value"); // put some stuff in the collection + map15760.put("keyB-15760", param); // put it in a collection + map15760.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map15760.get("keyB-15760"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02077.java b/OWASP DATASET/BenchmarkTest02077.java new file mode 100644 index 0000000000000000000000000000000000000000..6ad0a107ac482bb2fb594b8b78a3a79e9da93f1d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02077.java @@ -0,0 +1,147 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02077") +public class BenchmarkTest02077 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02077"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a78258 = param; // assign + StringBuilder b78258 = new StringBuilder(a78258); // stick in stringbuilder + b78258.append(" SafeStuff"); // append some safe content + b78258.replace( + b78258.length() - "Chars".length(), + b78258.length(), + "Chars"); // replace some of the end content + java.util.HashMap map78258 = new java.util.HashMap(); + map78258.put("key78258", b78258.toString()); // put in a collection + String c78258 = (String) map78258.get("key78258"); // get it back out + String d78258 = c78258.substring(0, c78258.length() - 1); // extract most of it + String e78258 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d78258.getBytes()))); // B64 encode and decode it + String f78258 = e78258.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g78258 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g78258); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02078.java b/OWASP DATASET/BenchmarkTest02078.java new file mode 100644 index 0000000000000000000000000000000000000000..ba0a376ba8b50fe3afd71b20e4fc57ac35acecab --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02078.java @@ -0,0 +1,123 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02078") +public class BenchmarkTest02078 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02078"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02079.java b/OWASP DATASET/BenchmarkTest02079.java new file mode 100644 index 0000000000000000000000000000000000000000..28f795914b33f2885e367087b210c5ad2744f5c6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02079.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02079") +public class BenchmarkTest02079 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02079"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + double stuff = java.security.SecureRandom.getInstance("SHA1PRNG").nextGaussian(); + String rememberMeKey = + Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "SafeGayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextGaussian() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextGaussian() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02080.java b/OWASP DATASET/BenchmarkTest02080.java new file mode 100644 index 0000000000000000000000000000000000000000..55738d0768b8cabb5bc27d88427f8da65c16b93a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02080.java @@ -0,0 +1,128 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02080") +public class BenchmarkTest02080 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02080"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + double stuff = java.security.SecureRandom.getInstance("SHA1PRNG").nextGaussian(); + String rememberMeKey = + Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "SafeGayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextGaussian() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextGaussian() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02081.java b/OWASP DATASET/BenchmarkTest02081.java new file mode 100644 index 0000000000000000000000000000000000000000..827b9ef9aefe00036f7087539a1778da732174d5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02081.java @@ -0,0 +1,137 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02081") +public class BenchmarkTest02081 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02081"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + int randNumber = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "SafeInga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt(int) - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt(int) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a44156 = param; // assign + StringBuilder b44156 = new StringBuilder(a44156); // stick in stringbuilder + b44156.append(" SafeStuff"); // append some safe content + b44156.replace( + b44156.length() - "Chars".length(), + b44156.length(), + "Chars"); // replace some of the end content + java.util.HashMap map44156 = new java.util.HashMap(); + map44156.put("key44156", b44156.toString()); // put in a collection + String c44156 = (String) map44156.get("key44156"); // get it back out + String d44156 = c44156.substring(0, c44156.length() - 1); // extract most of it + String e44156 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d44156.getBytes()))); // B64 encode and decode it + String f44156 = e44156.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f44156); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02082.java b/OWASP DATASET/BenchmarkTest02082.java new file mode 100644 index 0000000000000000000000000000000000000000..a0750aad4b8bb4854a1c033d0c1ef303cde75150 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02082.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02082") +public class BenchmarkTest02082 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02082"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + int r = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "SafeIngrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02083.java b/OWASP DATASET/BenchmarkTest02083.java new file mode 100644 index 0000000000000000000000000000000000000000..12783e265aa228930ede8a8693e1c7e7a3ce5bf1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02083.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02083") +public class BenchmarkTest02083 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02083"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + long l = java.security.SecureRandom.getInstance("SHA1PRNG").nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "SafeLogan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextLong() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextLong() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02084.java b/OWASP DATASET/BenchmarkTest02084.java new file mode 100644 index 0000000000000000000000000000000000000000..9f810fe2a3d05517870ee1314ff9490834e13bba --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02084.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest02084") +public class BenchmarkTest02084 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02084"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02085.java b/OWASP DATASET/BenchmarkTest02085.java new file mode 100644 index 0000000000000000000000000000000000000000..bf265eb7ee1081e19c715bc9b6024d193a4cc0b8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02085.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest02085") +public class BenchmarkTest02085 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02085"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02086.java b/OWASP DATASET/BenchmarkTest02086.java new file mode 100644 index 0000000000000000000000000000000000000000..9bad930644737aa0093e61835f139adea7170551 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02086.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest02086") +public class BenchmarkTest02086 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02086"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02087.java b/OWASP DATASET/BenchmarkTest02087.java new file mode 100644 index 0000000000000000000000000000000000000000..41825b6aa833f7d17656c98cde212e196f0d0930 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02087.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02087") +public class BenchmarkTest02087 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02087"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02088.java b/OWASP DATASET/BenchmarkTest02088.java new file mode 100644 index 0000000000000000000000000000000000000000..d7221da5d40b5f70e6c02a834ede95b74cf4c1e9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02088.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02088") +public class BenchmarkTest02088 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02088"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02089.java b/OWASP DATASET/BenchmarkTest02089.java new file mode 100644 index 0000000000000000000000000000000000000000..a5867c1b738549c8e8bd4cef01e24639f19a7244 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02089.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02089") +public class BenchmarkTest02089 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02089"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02090.java b/OWASP DATASET/BenchmarkTest02090.java new file mode 100644 index 0000000000000000000000000000000000000000..a79d032702d8ddd36e5702b36badb1ab41ce48dc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02090.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02090") +public class BenchmarkTest02090 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02090"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.execute(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring execute method doesn't return results."); + + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02091.java b/OWASP DATASET/BenchmarkTest02091.java new file mode 100644 index 0000000000000000000000000000000000000000..6e5814906b544336fa4d110d35d87a6dcb04425f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02091.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02091") +public class BenchmarkTest02091 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02091"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.query( + sql, + new org.springframework.jdbc.core.RowMapper() { + @Override + public String mapRow(java.sql.ResultSet rs, int rowNum) + throws java.sql.SQLException { + try { + return rs.getString("USERNAME"); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper + .hideSQLErrors) { + return "Error processing query."; + } else throw e; + } + } + }); + response.getWriter().println("Your results are: "); + + for (String s : results) { + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(s) + "
"); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02092.java b/OWASP DATASET/BenchmarkTest02092.java new file mode 100644 index 0000000000000000000000000000000000000000..669ee4c7ee9eae7af6e1029534325f06ad3b0bdd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02092.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02092") +public class BenchmarkTest02092 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02092"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02093.java b/OWASP DATASET/BenchmarkTest02093.java new file mode 100644 index 0000000000000000000000000000000000000000..62bad61b554fec90093dac310e67d45d0dfff969 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02093.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02093") +public class BenchmarkTest02093 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02093"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02094.java b/OWASP DATASET/BenchmarkTest02094.java new file mode 100644 index 0000000000000000000000000000000000000000..1bd07a5103280209de40251b5af45f6047e1cee7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02094.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02094") +public class BenchmarkTest02094 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02094"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02095.java b/OWASP DATASET/BenchmarkTest02095.java new file mode 100644 index 0000000000000000000000000000000000000000..9e58f570310ae7a8738725a491737bf28b453702 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02095.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02095") +public class BenchmarkTest02095 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02095"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map43923 = new java.util.HashMap(); + map43923.put("keyA-43923", "a_Value"); // put some stuff in the collection + map43923.put("keyB-43923", param); // put it in a collection + map43923.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map43923.get("keyB-43923"); // get it back out + bar = (String) map43923.get("keyA-43923"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02096.java b/OWASP DATASET/BenchmarkTest02096.java new file mode 100644 index 0000000000000000000000000000000000000000..0b69ffd348c48fae28b17895aaf7a16bef142a75 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02096.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02096") +public class BenchmarkTest02096 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02096"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02097.java b/OWASP DATASET/BenchmarkTest02097.java new file mode 100644 index 0000000000000000000000000000000000000000..a34bc2846d6321f43465a9af0562566a1734f55a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02097.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02097") +public class BenchmarkTest02097 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02097"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + java.sql.ResultSet rs = statement.executeQuery(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map94015 = new java.util.HashMap(); + map94015.put("keyA-94015", "a_Value"); // put some stuff in the collection + map94015.put("keyB-94015", param); // put it in a collection + map94015.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map94015.get("keyB-94015"); // get it back out + bar = (String) map94015.get("keyA-94015"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02098.java b/OWASP DATASET/BenchmarkTest02098.java new file mode 100644 index 0000000000000000000000000000000000000000..3df3672ee353ed90cc0f6a0cdc24e6c039e8150a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02098.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02098") +public class BenchmarkTest02098 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02098"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + java.sql.ResultSet rs = statement.executeQuery(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02099.java b/OWASP DATASET/BenchmarkTest02099.java new file mode 100644 index 0000000000000000000000000000000000000000..c68f1bc5828ce5df2e89f8b36e1f173b60c51c6a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02099.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02099") +public class BenchmarkTest02099 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02099"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02100.java b/OWASP DATASET/BenchmarkTest02100.java new file mode 100644 index 0000000000000000000000000000000000000000..63b61d1f8af3ae002d57a8e3fbaaccbac56b5a04 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02100.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest02100") +public class BenchmarkTest02100 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + java.util.Enumeration headers = request.getHeaders("BenchmarkTest02100"); + + if (headers != null && headers.hasMoreElements()) { + param = headers.nextElement(); // just grab first element + } + + // URL Decode the header value since req.getHeaders() doesn't. Unlike req.getParameters(). + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + org.w3c.dom.NodeList nodeList = + (org.w3c.dom.NodeList) + xp.compile(expression) + .evaluate(xmlDocument, javax.xml.xpath.XPathConstants.NODESET); + + response.getWriter().println("Your query results are:
"); + + for (int i = 0; i < nodeList.getLength(); i++) { + org.w3c.dom.Element value = (org.w3c.dom.Element) nodeList.item(i); + response.getWriter().println(value.getTextContent() + "
"); + } + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02101.java b/OWASP DATASET/BenchmarkTest02101.java new file mode 100644 index 0000000000000000000000000000000000000000..1930744b9bd68d3b8a34e2eed57d79267a1f8115 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02101.java @@ -0,0 +1,163 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02101") +public class BenchmarkTest02101 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02101"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02102.java b/OWASP DATASET/BenchmarkTest02102.java new file mode 100644 index 0000000000000000000000000000000000000000..9a09a0988eac73dcda03e706bfe92b019da2aed3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02102.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02102") +public class BenchmarkTest02102 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02102"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = org.owasp.benchmark.helpers.Utils.getCipher(); + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz85369 = new StringBuilder(param); + bar = sbxyz85369.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02103.java b/OWASP DATASET/BenchmarkTest02103.java new file mode 100644 index 0000000000000000000000000000000000000000..4ab83895b03e2f6e7f7dd948a0b0078f83cfaaea --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02103.java @@ -0,0 +1,132 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02103") +public class BenchmarkTest02103 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02103"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + // java.security.SecureRandom random = new java.security.SecureRandom(); + // byte[] iv = random.generateSeed(16); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg2", "AES/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02104.java b/OWASP DATASET/BenchmarkTest02104.java new file mode 100644 index 0000000000000000000000000000000000000000..63ddf9e267a3fce7849a7145c2cc4d1785cae539 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02104.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest02104") +public class BenchmarkTest02104 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02104"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + javax.naming.directory.DirContext ctx = ads.getDirContext(); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + bar + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + // System.out.println("Filter " + filter); + boolean found = false; + javax.naming.NamingEnumeration results = + ctx.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02105.java b/OWASP DATASET/BenchmarkTest02105.java new file mode 100644 index 0000000000000000000000000000000000000000..058b1e2c8d5a9c826568137d05b9c5a3629843d5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02105.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02105") +public class BenchmarkTest02105 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02105"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + java.io.File fileTarget = + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR, bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02106.java b/OWASP DATASET/BenchmarkTest02106.java new file mode 100644 index 0000000000000000000000000000000000000000..e1f8a4c5862ad4c5fc79a484523a9501f018327b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02106.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02106") +public class BenchmarkTest02106 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02106"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + java.io.File fileTarget = new java.io.File(bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02107.java b/OWASP DATASET/BenchmarkTest02107.java new file mode 100644 index 0000000000000000000000000000000000000000..acb89d78ab3eafa015eaaa70046c3932f001af76 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02107.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02107") +public class BenchmarkTest02107 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02107"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + java.io.File fileTarget = new java.io.File(bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02108.java b/OWASP DATASET/BenchmarkTest02108.java new file mode 100644 index 0000000000000000000000000000000000000000..7111fdf9d1bd83fb5218afb9cf84bc5eca430d03 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02108.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02108") +public class BenchmarkTest02108 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02108"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName), false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map44255 = new java.util.HashMap(); + map44255.put("keyA-44255", "a_Value"); // put some stuff in the collection + map44255.put("keyB-44255", param); // put it in a collection + map44255.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map44255.get("keyB-44255"); // get it back out + bar = (String) map44255.get("keyA-44255"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02109.java b/OWASP DATASET/BenchmarkTest02109.java new file mode 100644 index 0000000000000000000000000000000000000000..baa9a5756414ff981bab0a49253f7088d64b7aac --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02109.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02109") +public class BenchmarkTest02109 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02109"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName)); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02110.java b/OWASP DATASET/BenchmarkTest02110.java new file mode 100644 index 0000000000000000000000000000000000000000..e792992132e1ad70bdc19c23d6df63d60619f5a0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02110.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02110") +public class BenchmarkTest02110 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02110"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName)); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02111.java b/OWASP DATASET/BenchmarkTest02111.java new file mode 100644 index 0000000000000000000000000000000000000000..c7e4f0bbdd3d78517961331881292bf10156bcbf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02111.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02111") +public class BenchmarkTest02111 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02111"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + try ( + // Create the file first so the test won't throw an exception if it doesn't exist. + // Note: Don't actually do this because this method signature could cause a tool to find + // THIS file constructor + // as a vuln, rather than the File signature we are trying to actually test. + // If necessary, just run the benchmark twice. The 1st run should create all the necessary + // files. + // new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar).createNewFile(); + + java.io.FileOutputStream fos = + new java.io.FileOutputStream(new java.io.FileInputStream(fileName).getFD()); ) { + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02112.java b/OWASP DATASET/BenchmarkTest02112.java new file mode 100644 index 0000000000000000000000000000000000000000..54382ed0a93d1f3b2bb54c2cde53ba12b575e16d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02112.java @@ -0,0 +1,101 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02112") +public class BenchmarkTest02112 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02112"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName, false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02113.java b/OWASP DATASET/BenchmarkTest02113.java new file mode 100644 index 0000000000000000000000000000000000000000..c775f93bbacb375e246294dc47090ed557dd949e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02113.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02113") +public class BenchmarkTest02113 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02113"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + java.io.InputStream is = null; + + try { + java.nio.file.Path path = java.nio.file.Paths.get(fileName); + is = java.nio.file.Files.newInputStream(path, java.nio.file.StandardOpenOption.READ); + byte[] b = new byte[1000]; + int size = is.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + is.close(); + } catch (Exception e) { + System.out.println("Couldn't open InputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting InputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (is != null) { + try { + is.close(); + is = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02114.java b/OWASP DATASET/BenchmarkTest02114.java new file mode 100644 index 0000000000000000000000000000000000000000..42e5b583976b7d5988ad1d5f22c3acfa2b6212e8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02114.java @@ -0,0 +1,118 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest02114") +public class BenchmarkTest02114 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02114"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + bar + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + + javax.naming.directory.DirContext ctx = ads.getDirContext(); + javax.naming.directory.InitialDirContext idc = + (javax.naming.directory.InitialDirContext) ctx; + boolean found = false; + javax.naming.NamingEnumeration results = + idc.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02115.java b/OWASP DATASET/BenchmarkTest02115.java new file mode 100644 index 0000000000000000000000000000000000000000..dbc0bc3d18fe7bf07c537d214ad9f1425374409c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02115.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest02115") +public class BenchmarkTest02115 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02115"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + bar + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + + javax.naming.directory.DirContext ctx = ads.getDirContext(); + javax.naming.directory.InitialDirContext idc = + (javax.naming.directory.InitialDirContext) ctx; + boolean found = false; + javax.naming.NamingEnumeration results = + idc.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map89109 = new java.util.HashMap(); + map89109.put("keyA-89109", "a_Value"); // put some stuff in the collection + map89109.put("keyB-89109", param); // put it in a collection + map89109.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map89109.get("keyB-89109"); // get it back out + bar = (String) map89109.get("keyA-89109"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02116.java b/OWASP DATASET/BenchmarkTest02116.java new file mode 100644 index 0000000000000000000000000000000000000000..a1dc8d7ca11d8cd867984282fb7d6dbc6529529a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02116.java @@ -0,0 +1,127 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest02116") +public class BenchmarkTest02116 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02116"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person)(uid=" + bar + "))"; + + javax.naming.directory.DirContext ctx = ads.getDirContext(); + javax.naming.directory.InitialDirContext idc = + (javax.naming.directory.InitialDirContext) ctx; + boolean found = false; + javax.naming.NamingEnumeration results = + idc.search(base, filter, sc); + + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02117.java b/OWASP DATASET/BenchmarkTest02117.java new file mode 100644 index 0000000000000000000000000000000000000000..4a05c53e24856d7a26b7c459b8315146bcb95c72 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02117.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02117") +public class BenchmarkTest02117 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02117"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + double value = java.lang.Math.random(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Doug"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + response.getWriter().println("Weak Randomness Test java.lang.Math.random() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map12987 = new java.util.HashMap(); + map12987.put("keyA-12987", "a-Value"); // put some stuff in the collection + map12987.put("keyB-12987", param); // put it in a collection + map12987.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map12987.get("keyB-12987"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02118.java b/OWASP DATASET/BenchmarkTest02118.java new file mode 100644 index 0000000000000000000000000000000000000000..53fe8213389c4008d3f16e4118f8eece00cb95fa --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02118.java @@ -0,0 +1,123 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02118") +public class BenchmarkTest02118 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02118"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("SHA1", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02119.java b/OWASP DATASET/BenchmarkTest02119.java new file mode 100644 index 0000000000000000000000000000000000000000..e81475361111a397a75469d08b67d11f0903d580 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02119.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02119") +public class BenchmarkTest02119 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02119"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = + java.security.MessageDigest.getInstance("SHA-512", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map70096 = new java.util.HashMap(); + map70096.put("keyA-70096", "a-Value"); // put some stuff in the collection + map70096.put("keyB-70096", param); // put it in a collection + map70096.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map70096.get("keyB-70096"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02120.java b/OWASP DATASET/BenchmarkTest02120.java new file mode 100644 index 0000000000000000000000000000000000000000..db5d2486359098acddc20c8a8299b93cb3c228d1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02120.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02120") +public class BenchmarkTest02120 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02120"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-256"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02121.java b/OWASP DATASET/BenchmarkTest02121.java new file mode 100644 index 0000000000000000000000000000000000000000..c4a545536cc60197cb998f588aa2050fb10a40e4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02121.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02121") +public class BenchmarkTest02121 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02121"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02122.java b/OWASP DATASET/BenchmarkTest02122.java new file mode 100644 index 0000000000000000000000000000000000000000..b1d3c0658f2ce3367f4187d0828faaeedd7bed13 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02122.java @@ -0,0 +1,73 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-03/BenchmarkTest02122") +public class BenchmarkTest02122 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02122"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + java.io.PrintWriter out = response.getWriter(); + out.write("\n\n\n

"); + out.format(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + out.write("\n

\n\n"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02123.java b/OWASP DATASET/BenchmarkTest02123.java new file mode 100644 index 0000000000000000000000000000000000000000..ca56b64dc44f24ac68d0d7eff89f4a1ab3476295 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02123.java @@ -0,0 +1,62 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02123") +public class BenchmarkTest02123 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02123"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().format("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02124.java b/OWASP DATASET/BenchmarkTest02124.java new file mode 100644 index 0000000000000000000000000000000000000000..42394ba69f99c5377415c341e132ded5398eda2c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02124.java @@ -0,0 +1,63 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02124") +public class BenchmarkTest02124 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02124"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar.toCharArray()); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz69250 = new StringBuilder(param); + bar = sbxyz69250.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02125.java b/OWASP DATASET/BenchmarkTest02125.java new file mode 100644 index 0000000000000000000000000000000000000000..292411b39ca52de3483f2a224452be093df122e6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02125.java @@ -0,0 +1,59 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02125") +public class BenchmarkTest02125 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02125"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02126.java b/OWASP DATASET/BenchmarkTest02126.java new file mode 100644 index 0000000000000000000000000000000000000000..d6c2d9216e81a265751bbc91c1722718f3b68d0f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02126.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02126") +public class BenchmarkTest02126 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02126"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a64181 = param; // assign + StringBuilder b64181 = new StringBuilder(a64181); // stick in stringbuilder + b64181.append(" SafeStuff"); // append some safe content + b64181.replace( + b64181.length() - "Chars".length(), + b64181.length(), + "Chars"); // replace some of the end content + java.util.HashMap map64181 = new java.util.HashMap(); + map64181.put("key64181", b64181.toString()); // put in a collection + String c64181 = (String) map64181.get("key64181"); // get it back out + String d64181 = c64181.substring(0, c64181.length() - 1); // extract most of it + String e64181 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d64181.getBytes()))); // B64 encode and decode it + String f64181 = e64181.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f64181); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02127.java b/OWASP DATASET/BenchmarkTest02127.java new file mode 100644 index 0000000000000000000000000000000000000000..887f06f7536e4033cbdeefb9cb339f0ff15ecfd7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02127.java @@ -0,0 +1,64 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02127") +public class BenchmarkTest02127 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02127"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02128.java b/OWASP DATASET/BenchmarkTest02128.java new file mode 100644 index 0000000000000000000000000000000000000000..b805802fd5e7161cabab44f112e67ed7801f0244 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02128.java @@ -0,0 +1,62 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02128") +public class BenchmarkTest02128 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02128"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02129.java b/OWASP DATASET/BenchmarkTest02129.java new file mode 100644 index 0000000000000000000000000000000000000000..0ef4919c541c11eff2e6e1ad262bcc0c2ae24820 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02129.java @@ -0,0 +1,61 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02129") +public class BenchmarkTest02129 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02129"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02130.java b/OWASP DATASET/BenchmarkTest02130.java new file mode 100644 index 0000000000000000000000000000000000000000..815e4acba946c090c96fa91a35cd99813f73d6cd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02130.java @@ -0,0 +1,61 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02130") +public class BenchmarkTest02130 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02130"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz60224 = new StringBuilder(param); + String bar = sbxyz60224.append("_SafeStuff").toString(); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02131.java b/OWASP DATASET/BenchmarkTest02131.java new file mode 100644 index 0000000000000000000000000000000000000000..85eacdf529f970448ff05242095fe254af699164 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02131.java @@ -0,0 +1,63 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02131") +public class BenchmarkTest02131 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02131"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(java.util.Locale.US, bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02132.java b/OWASP DATASET/BenchmarkTest02132.java new file mode 100644 index 0000000000000000000000000000000000000000..b33a9666f2e262dc062c9f765b06c53d34198cbf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02132.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02132") +public class BenchmarkTest02132 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02132"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a76744 = param; // assign + StringBuilder b76744 = new StringBuilder(a76744); // stick in stringbuilder + b76744.append(" SafeStuff"); // append some safe content + b76744.replace( + b76744.length() - "Chars".length(), + b76744.length(), + "Chars"); // replace some of the end content + java.util.HashMap map76744 = new java.util.HashMap(); + map76744.put("key76744", b76744.toString()); // put in a collection + String c76744 = (String) map76744.get("key76744"); // get it back out + String d76744 = c76744.substring(0, c76744.length() - 1); // extract most of it + String e76744 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d76744.getBytes()))); // B64 encode and decode it + String f76744 = e76744.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f76744); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02133.java b/OWASP DATASET/BenchmarkTest02133.java new file mode 100644 index 0000000000000000000000000000000000000000..525363e6fca94778e7f0408d01c7d1bc1232c528 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02133.java @@ -0,0 +1,64 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02133") +public class BenchmarkTest02133 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02133"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02134.java b/OWASP DATASET/BenchmarkTest02134.java new file mode 100644 index 0000000000000000000000000000000000000000..56cfa69c072d49ed7b22813d5431f4ccffa312d4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02134.java @@ -0,0 +1,62 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02134") +public class BenchmarkTest02134 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02134"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar.toCharArray()); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02135.java b/OWASP DATASET/BenchmarkTest02135.java new file mode 100644 index 0000000000000000000000000000000000000000..000c66248dd45c65b4641633d0a0b9611918ec4a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02135.java @@ -0,0 +1,80 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02135") +public class BenchmarkTest02135 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02135"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a95930 = param; // assign + StringBuilder b95930 = new StringBuilder(a95930); // stick in stringbuilder + b95930.append(" SafeStuff"); // append some safe content + b95930.replace( + b95930.length() - "Chars".length(), + b95930.length(), + "Chars"); // replace some of the end content + java.util.HashMap map95930 = new java.util.HashMap(); + map95930.put("key95930", b95930.toString()); // put in a collection + String c95930 = (String) map95930.get("key95930"); // get it back out + String d95930 = c95930.substring(0, c95930.length() - 1); // extract most of it + String e95930 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d95930.getBytes()))); // B64 encode and decode it + String f95930 = e95930.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g95930 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g95930); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02136.java b/OWASP DATASET/BenchmarkTest02136.java new file mode 100644 index 0000000000000000000000000000000000000000..e92b64be22b885f924bb734b45865c3ab6f2104d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02136.java @@ -0,0 +1,68 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02136") +public class BenchmarkTest02136 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02136"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar, 0, length); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02137.java b/OWASP DATASET/BenchmarkTest02137.java new file mode 100644 index 0000000000000000000000000000000000000000..d25ef2956216d7b69a532464efb077e46ed49065 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02137.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02137") +public class BenchmarkTest02137 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02137"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(); + + pb.command(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02138.java b/OWASP DATASET/BenchmarkTest02138.java new file mode 100644 index 0000000000000000000000000000000000000000..50da3f1f59f5ca1687e52fd3d0c950b06580f64c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02138.java @@ -0,0 +1,111 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02138") +public class BenchmarkTest02138 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02138"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + byte[] bytes = new byte[10]; + new java.util.Random().nextBytes(bytes); + String rememberMeKey = org.owasp.esapi.ESAPI.encoder().encodeForBase64(bytes, true); + + String user = "Byron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextBytes() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02139.java b/OWASP DATASET/BenchmarkTest02139.java new file mode 100644 index 0000000000000000000000000000000000000000..b13525189d475102e549a82a8c3b6c2bf8a4aa61 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02139.java @@ -0,0 +1,105 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02139") +public class BenchmarkTest02139 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02139"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + float rand = new java.util.Random().nextFloat(); + String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "Floyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02140.java b/OWASP DATASET/BenchmarkTest02140.java new file mode 100644 index 0000000000000000000000000000000000000000..58c2eaa04776103a7c93d7086cd597259b336b95 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02140.java @@ -0,0 +1,111 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02140") +public class BenchmarkTest02140 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02140"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02141.java b/OWASP DATASET/BenchmarkTest02141.java new file mode 100644 index 0000000000000000000000000000000000000000..6bf79db86749a0d23c28e5bf3d71d64d59cbe820 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02141.java @@ -0,0 +1,105 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02141") +public class BenchmarkTest02141 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02141"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02142.java b/OWASP DATASET/BenchmarkTest02142.java new file mode 100644 index 0000000000000000000000000000000000000000..671b55445595f98d092d99bf409a01e8c735181c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02142.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest02142") +public class BenchmarkTest02142 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02142"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02143.java b/OWASP DATASET/BenchmarkTest02143.java new file mode 100644 index 0000000000000000000000000000000000000000..daed648eb85c92c6984a6b9dcf5bfa303b141b4c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02143.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest02143") +public class BenchmarkTest02143 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02143"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map44285 = new java.util.HashMap(); + map44285.put("keyA-44285", "a_Value"); // put some stuff in the collection + map44285.put("keyB-44285", param); // put it in a collection + map44285.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map44285.get("keyB-44285"); // get it back out + bar = (String) map44285.get("keyA-44285"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02144.java b/OWASP DATASET/BenchmarkTest02144.java new file mode 100644 index 0000000000000000000000000000000000000000..5db8352bb96d5800270ae5d3f986b12812bdf5bb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02144.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest02144") +public class BenchmarkTest02144 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02144"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02145.java b/OWASP DATASET/BenchmarkTest02145.java new file mode 100644 index 0000000000000000000000000000000000000000..d83254d0536adbf56b34771e541c3aa424f96f05 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02145.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02145") +public class BenchmarkTest02145 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02145"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write("Parameter value: " + bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a32743 = param; // assign + StringBuilder b32743 = new StringBuilder(a32743); // stick in stringbuilder + b32743.append(" SafeStuff"); // append some safe content + b32743.replace( + b32743.length() - "Chars".length(), + b32743.length(), + "Chars"); // replace some of the end content + java.util.HashMap map32743 = new java.util.HashMap(); + map32743.put("key32743", b32743.toString()); // put in a collection + String c32743 = (String) map32743.get("key32743"); // get it back out + String d32743 = c32743.substring(0, c32743.length() - 1); // extract most of it + String e32743 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d32743.getBytes()))); // B64 encode and decode it + String f32743 = e32743.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f32743); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02146.java b/OWASP DATASET/BenchmarkTest02146.java new file mode 100644 index 0000000000000000000000000000000000000000..faaee753c9bd29b146567df0c56ec06de4115834 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02146.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02146") +public class BenchmarkTest02146 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02146"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02147.java b/OWASP DATASET/BenchmarkTest02147.java new file mode 100644 index 0000000000000000000000000000000000000000..e5b87e810af4e4b277d07ccf3997809263510199 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02147.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02147") +public class BenchmarkTest02147 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02147"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02148.java b/OWASP DATASET/BenchmarkTest02148.java new file mode 100644 index 0000000000000000000000000000000000000000..d9efbca6ee56b8d1083ea64585d6e6e6d114c2f2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02148.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02148") +public class BenchmarkTest02148 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02148"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a17988 = param; // assign + StringBuilder b17988 = new StringBuilder(a17988); // stick in stringbuilder + b17988.append(" SafeStuff"); // append some safe content + b17988.replace( + b17988.length() - "Chars".length(), + b17988.length(), + "Chars"); // replace some of the end content + java.util.HashMap map17988 = new java.util.HashMap(); + map17988.put("key17988", b17988.toString()); // put in a collection + String c17988 = (String) map17988.get("key17988"); // get it back out + String d17988 = c17988.substring(0, c17988.length() - 1); // extract most of it + String e17988 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d17988.getBytes()))); // B64 encode and decode it + String f17988 = e17988.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g17988 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g17988); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02149.java b/OWASP DATASET/BenchmarkTest02149.java new file mode 100644 index 0000000000000000000000000000000000000000..77f899b2573bc0f7765724d2e8308d2a540dee77 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02149.java @@ -0,0 +1,93 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02149") +public class BenchmarkTest02149 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02149"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02150.java b/OWASP DATASET/BenchmarkTest02150.java new file mode 100644 index 0000000000000000000000000000000000000000..c0b1e17f6f2de75b034ec0f84820472522ed55d5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02150.java @@ -0,0 +1,107 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02150") +public class BenchmarkTest02150 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02150"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02151.java b/OWASP DATASET/BenchmarkTest02151.java new file mode 100644 index 0000000000000000000000000000000000000000..45e621ee925e1890c63935c118f14e4f49073766 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02151.java @@ -0,0 +1,98 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02151") +public class BenchmarkTest02151 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02151"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02152.java b/OWASP DATASET/BenchmarkTest02152.java new file mode 100644 index 0000000000000000000000000000000000000000..e87508dbf9052539ec0b277c3a52c95228f68c41 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02152.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02152") +public class BenchmarkTest02152 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02152"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02153.java b/OWASP DATASET/BenchmarkTest02153.java new file mode 100644 index 0000000000000000000000000000000000000000..54c7827c4abb1bbb2cb8ebca96a29d9dd3201d6a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02153.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02153") +public class BenchmarkTest02153 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02153"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a82592 = param; // assign + StringBuilder b82592 = new StringBuilder(a82592); // stick in stringbuilder + b82592.append(" SafeStuff"); // append some safe content + b82592.replace( + b82592.length() - "Chars".length(), + b82592.length(), + "Chars"); // replace some of the end content + java.util.HashMap map82592 = new java.util.HashMap(); + map82592.put("key82592", b82592.toString()); // put in a collection + String c82592 = (String) map82592.get("key82592"); // get it back out + String d82592 = c82592.substring(0, c82592.length() - 1); // extract most of it + String e82592 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d82592.getBytes()))); // B64 encode and decode it + String f82592 = e82592.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g82592 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g82592); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02154.java b/OWASP DATASET/BenchmarkTest02154.java new file mode 100644 index 0000000000000000000000000000000000000000..b989c97c0320fc824b5809f589ff70738037e8a5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02154.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02154") +public class BenchmarkTest02154 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02154"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = + r.exec(cmd + bar, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02155.java b/OWASP DATASET/BenchmarkTest02155.java new file mode 100644 index 0000000000000000000000000000000000000000..8dea5d4ceb277cae129bc37bc0f09a144fc3d4bc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02155.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02155") +public class BenchmarkTest02155 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02155"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + try { + Process p = r.exec(cmd, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02156.java b/OWASP DATASET/BenchmarkTest02156.java new file mode 100644 index 0000000000000000000000000000000000000000..5e1c14db534a68e816b8c604fc52f222e98f491b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02156.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02156") +public class BenchmarkTest02156 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02156"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + try { + Process p = r.exec(cmd, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02157.java b/OWASP DATASET/BenchmarkTest02157.java new file mode 100644 index 0000000000000000000000000000000000000000..776e92431aefb66f02b619442bb3f18b1d5bb0e6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02157.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02157") +public class BenchmarkTest02157 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02157"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + getNextNumber(numGen, randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeBystander"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + void getNextNumber(java.util.Random generator, byte[] barray) { + generator.nextBytes(barray); + } + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02158.java b/OWASP DATASET/BenchmarkTest02158.java new file mode 100644 index 0000000000000000000000000000000000000000..230d185a070485849268bcb5a1ce84cbeb04195b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02158.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-04/BenchmarkTest02158") +public class BenchmarkTest02158 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02158"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02159.java b/OWASP DATASET/BenchmarkTest02159.java new file mode 100644 index 0000000000000000000000000000000000000000..b005fa93436a8a94164059749d29fbf729a6a47f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02159.java @@ -0,0 +1,133 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02159") +public class BenchmarkTest02159 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02159"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a66015 = param; // assign + StringBuilder b66015 = new StringBuilder(a66015); // stick in stringbuilder + b66015.append(" SafeStuff"); // append some safe content + b66015.replace( + b66015.length() - "Chars".length(), + b66015.length(), + "Chars"); // replace some of the end content + java.util.HashMap map66015 = new java.util.HashMap(); + map66015.put("key66015", b66015.toString()); // put in a collection + String c66015 = (String) map66015.get("key66015"); // get it back out + String d66015 = c66015.substring(0, c66015.length() - 1); // extract most of it + String e66015 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d66015.getBytes()))); // B64 encode and decode it + String f66015 = e66015.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f66015); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02160.java b/OWASP DATASET/BenchmarkTest02160.java new file mode 100644 index 0000000000000000000000000000000000000000..c221e06bb0306cfcae672ca3e07dc4e89005ca65 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02160.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02160") +public class BenchmarkTest02160 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02160"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + double rand = getNextNumber(numGen); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonatella"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + double getNextNumber(java.util.Random generator) { + return generator.nextDouble(); + } + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map25458 = new java.util.HashMap(); + map25458.put("keyA-25458", "a_Value"); // put some stuff in the collection + map25458.put("keyB-25458", param); // put it in a collection + map25458.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map25458.get("keyB-25458"); // get it back out + bar = (String) map25458.get("keyA-25458"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02161.java b/OWASP DATASET/BenchmarkTest02161.java new file mode 100644 index 0000000000000000000000000000000000000000..29d2b21dcfbf67cddfe152fccbd9e33ea8820435 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02161.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02161") +public class BenchmarkTest02161 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02161"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + int randNumber = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "SafeInga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt(int) - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt(int) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02162.java b/OWASP DATASET/BenchmarkTest02162.java new file mode 100644 index 0000000000000000000000000000000000000000..c0789684a0977931d98f0cb93664950f6ac014da --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02162.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02162") +public class BenchmarkTest02162 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02162"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + int r = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "SafeIngrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02163.java b/OWASP DATASET/BenchmarkTest02163.java new file mode 100644 index 0000000000000000000000000000000000000000..9203925d5d91e34c33bb24d35d37a6b5f3ba1ded --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02163.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02163") +public class BenchmarkTest02163 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02163"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + long l = java.security.SecureRandom.getInstance("SHA1PRNG").nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "SafeLogan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextLong() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextLong() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02164.java b/OWASP DATASET/BenchmarkTest02164.java new file mode 100644 index 0000000000000000000000000000000000000000..151beb6a0903cc2454bf45da4245715e0646c4f8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02164.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02164") +public class BenchmarkTest02164 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02164"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + long l = java.security.SecureRandom.getInstance("SHA1PRNG").nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "SafeLogan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextLong() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextLong() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02165.java b/OWASP DATASET/BenchmarkTest02165.java new file mode 100644 index 0000000000000000000000000000000000000000..92adf8ed4aa5d59c104a32f187313bb68cbbd0f4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02165.java @@ -0,0 +1,65 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest02165") +public class BenchmarkTest02165 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02165"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String^,java.lang.Object) + request.getSession().putValue(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: 10340 saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02166.java b/OWASP DATASET/BenchmarkTest02166.java new file mode 100644 index 0000000000000000000000000000000000000000..6ed257521ee75054baa08a68f2e2243af4438e7f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02166.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest02166") +public class BenchmarkTest02166 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02166"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02167.java b/OWASP DATASET/BenchmarkTest02167.java new file mode 100644 index 0000000000000000000000000000000000000000..b674146f9cab88d59bddc573aac162b798ff3dbd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02167.java @@ -0,0 +1,67 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest02167") +public class BenchmarkTest02167 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02167"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02168.java b/OWASP DATASET/BenchmarkTest02168.java new file mode 100644 index 0000000000000000000000000000000000000000..056ae5012f51e2a92d78dfe3b00e8be54ca3ff80 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02168.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest02168") +public class BenchmarkTest02168 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02168"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02169.java b/OWASP DATASET/BenchmarkTest02169.java new file mode 100644 index 0000000000000000000000000000000000000000..0e7ff768c71229e18a92411ff8826eddcd4ec614 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02169.java @@ -0,0 +1,80 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02169") +public class BenchmarkTest02169 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02169"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02170.java b/OWASP DATASET/BenchmarkTest02170.java new file mode 100644 index 0000000000000000000000000000000000000000..04587551cdc745bc6fecb3dffb0c66bb2dac8b69 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02170.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02170") +public class BenchmarkTest02170 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02170"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02171.java b/OWASP DATASET/BenchmarkTest02171.java new file mode 100644 index 0000000000000000000000000000000000000000..5456ea5f8d27e111af1cda578e0920317bb7d492 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02171.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02171") +public class BenchmarkTest02171 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02171"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02172.java b/OWASP DATASET/BenchmarkTest02172.java new file mode 100644 index 0000000000000000000000000000000000000000..aeeee038af17ff315ec5c5c90a4ea49238302864 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02172.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02172") +public class BenchmarkTest02172 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02172"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02173.java b/OWASP DATASET/BenchmarkTest02173.java new file mode 100644 index 0000000000000000000000000000000000000000..e26a2f320a677fcff7a930e885fb1c5a90845baa --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02173.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02173") +public class BenchmarkTest02173 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02173"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02174.java b/OWASP DATASET/BenchmarkTest02174.java new file mode 100644 index 0000000000000000000000000000000000000000..7f03611b7bd1a93825933c94e30a5d4c5e3f09e6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02174.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02174") +public class BenchmarkTest02174 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02174"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + // System.out.println("no results for query: " + sql + " because the Spring batchUpdate + // method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02175.java b/OWASP DATASET/BenchmarkTest02175.java new file mode 100644 index 0000000000000000000000000000000000000000..4a8edc6a7672e80b1448192d910a69f4351eb26a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02175.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02175") +public class BenchmarkTest02175 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02175"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.execute(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring execute method doesn't return results."); + + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02176.java b/OWASP DATASET/BenchmarkTest02176.java new file mode 100644 index 0000000000000000000000000000000000000000..98d9985b1edd5cb503ea5c37d298a15cb5d3c0b4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02176.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02176") +public class BenchmarkTest02176 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02176"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.execute(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring execute method doesn't return results."); + + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02177.java b/OWASP DATASET/BenchmarkTest02177.java new file mode 100644 index 0000000000000000000000000000000000000000..5a3a0bef1031a58bfe571c13d6d5f235d4d94d7f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02177.java @@ -0,0 +1,111 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02177") +public class BenchmarkTest02177 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02177"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.query( + sql, + new org.springframework.jdbc.core.RowMapper() { + @Override + public String mapRow(java.sql.ResultSet rs, int rowNum) + throws java.sql.SQLException { + try { + return rs.getString("USERNAME"); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper + .hideSQLErrors) { + return "Error processing query."; + } else throw e; + } + } + }); + response.getWriter().println("Your results are: "); + + for (String s : results) { + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(s) + "
"); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02178.java b/OWASP DATASET/BenchmarkTest02178.java new file mode 100644 index 0000000000000000000000000000000000000000..9fb366b9fbb87f672800b6482fd3a9c4513282cb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02178.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02178") +public class BenchmarkTest02178 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02178"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List> list = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForList(sql); + response.getWriter().println("Your results are:
"); + + // System.out.println("Your results are"); + + for (Object o : list) { + response.getWriter() + .println( + org.owasp.esapi.ESAPI.encoder().encodeForHTML(o.toString()) + + "
"); + // System.out.println(o.toString()); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map38026 = new java.util.HashMap(); + map38026.put("keyA-38026", "a-Value"); // put some stuff in the collection + map38026.put("keyB-38026", param); // put it in a collection + map38026.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map38026.get("keyB-38026"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02179.java b/OWASP DATASET/BenchmarkTest02179.java new file mode 100644 index 0000000000000000000000000000000000000000..7c64a0ddb2b055ab991f2fbe5520310d2d9d6964 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02179.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02179") +public class BenchmarkTest02179 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02179"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // Long results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForLong(sql); + Long results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Long.class); + response.getWriter().println("Your results are: " + String.valueOf(results)); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02180.java b/OWASP DATASET/BenchmarkTest02180.java new file mode 100644 index 0000000000000000000000000000000000000000..9f3ca18c83c2942929e5eb15c156652dbc0efd82 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02180.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02180") +public class BenchmarkTest02180 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02180"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // Long results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForLong(sql); + Long results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Long.class); + response.getWriter().println("Your results are: " + String.valueOf(results)); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map32515 = new java.util.HashMap(); + map32515.put("keyA-32515", "a_Value"); // put some stuff in the collection + map32515.put("keyB-32515", param); // put it in a collection + map32515.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map32515.get("keyB-32515"); // get it back out + bar = (String) map32515.get("keyA-32515"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02181.java b/OWASP DATASET/BenchmarkTest02181.java new file mode 100644 index 0000000000000000000000000000000000000000..15b365ce9e8c9ffcfdfda888fc22e1505722c482 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02181.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02181") +public class BenchmarkTest02181 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02181"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String sql = + "SELECT TOP 1 userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.Map results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForMap(sql); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(results.toString())); + // System.out.println(results.toString()); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02182.java b/OWASP DATASET/BenchmarkTest02182.java new file mode 100644 index 0000000000000000000000000000000000000000..f2e08c96a027dcc3833a9f1dff8a1fc70e89a823 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02182.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02182") +public class BenchmarkTest02182 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02182"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String sql = + "SELECT TOP 1 userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.Map results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForMap(sql); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(results.toString())); + // System.out.println(results.toString()); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02183.java b/OWASP DATASET/BenchmarkTest02183.java new file mode 100644 index 0000000000000000000000000000000000000000..4d2a03d9513f9a8398272716186af82d02bcbea4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02183.java @@ -0,0 +1,100 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02183") +public class BenchmarkTest02183 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02183"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String sql = + "SELECT TOP 1 USERNAME from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + Object results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, new Object[] {}, String.class); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(results.toString())); + // System.out.println(results.toString()); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a90580 = param; // assign + StringBuilder b90580 = new StringBuilder(a90580); // stick in stringbuilder + b90580.append(" SafeStuff"); // append some safe content + b90580.replace( + b90580.length() - "Chars".length(), + b90580.length(), + "Chars"); // replace some of the end content + java.util.HashMap map90580 = new java.util.HashMap(); + map90580.put("key90580", b90580.toString()); // put in a collection + String c90580 = (String) map90580.get("key90580"); // get it back out + String d90580 = c90580.substring(0, c90580.length() - 1); // extract most of it + String e90580 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d90580.getBytes()))); // B64 encode and decode it + String f90580 = e90580.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g90580 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g90580); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02184.java b/OWASP DATASET/BenchmarkTest02184.java new file mode 100644 index 0000000000000000000000000000000000000000..440e5401741a645ae5481aa005a3e72bffc0b21a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02184.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02184") +public class BenchmarkTest02184 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02184"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + org.springframework.jdbc.support.rowset.SqlRowSet results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForRowSet(sql); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + while (results.next()) { + response.getWriter() + .println( + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(results.getString("USERNAME")) + + " "); + // System.out.println(results.getString("USERNAME")); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02185.java b/OWASP DATASET/BenchmarkTest02185.java new file mode 100644 index 0000000000000000000000000000000000000000..4deedfcbebba0c3fe7ff6ea7ef69aa772929edc8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02185.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02185") +public class BenchmarkTest02185 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02185"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.addBatch(sql); + int[] counts = statement.executeBatch(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(sql, counts, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02186.java b/OWASP DATASET/BenchmarkTest02186.java new file mode 100644 index 0000000000000000000000000000000000000000..2585b309c068f75b2454d0b6fbd27ef9532c73cd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02186.java @@ -0,0 +1,72 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02186") +public class BenchmarkTest02186 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02186"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02187.java b/OWASP DATASET/BenchmarkTest02187.java new file mode 100644 index 0000000000000000000000000000000000000000..6333aeed5f16322b1eea56f8af2151f854a469e0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02187.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02187") +public class BenchmarkTest02187 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02187"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02188.java b/OWASP DATASET/BenchmarkTest02188.java new file mode 100644 index 0000000000000000000000000000000000000000..ff72471884d69f8fb4374e5b8e191740cadda359 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02188.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02188") +public class BenchmarkTest02188 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02188"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + java.sql.ResultSet rs = statement.executeQuery(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a16667 = param; // assign + StringBuilder b16667 = new StringBuilder(a16667); // stick in stringbuilder + b16667.append(" SafeStuff"); // append some safe content + b16667.replace( + b16667.length() - "Chars".length(), + b16667.length(), + "Chars"); // replace some of the end content + java.util.HashMap map16667 = new java.util.HashMap(); + map16667.put("key16667", b16667.toString()); // put in a collection + String c16667 = (String) map16667.get("key16667"); // get it back out + String d16667 = c16667.substring(0, c16667.length() - 1); // extract most of it + String e16667 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d16667.getBytes()))); // B64 encode and decode it + String f16667 = e16667.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g16667 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g16667); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02189.java b/OWASP DATASET/BenchmarkTest02189.java new file mode 100644 index 0000000000000000000000000000000000000000..af05e26635caf0af99543dbb1a148920b0dacdc1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02189.java @@ -0,0 +1,93 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest02189") +public class BenchmarkTest02189 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = request.getParameter("BenchmarkTest02189"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + org.w3c.dom.NodeList nodeList = + (org.w3c.dom.NodeList) + xp.compile(expression) + .evaluate(xmlDocument, javax.xml.xpath.XPathConstants.NODESET); + + response.getWriter().println("Your query results are:
"); + + for (int i = 0; i < nodeList.getLength(); i++) { + org.w3c.dom.Element value = (org.w3c.dom.Element) nodeList.item(i); + response.getWriter().println(value.getTextContent() + "
"); + } + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02190.java b/OWASP DATASET/BenchmarkTest02190.java new file mode 100644 index 0000000000000000000000000000000000000000..16c3374b0899d1eaae8aa65b0148903d3e398af5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02190.java @@ -0,0 +1,161 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02190") +public class BenchmarkTest02190 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02190"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02191.java b/OWASP DATASET/BenchmarkTest02191.java new file mode 100644 index 0000000000000000000000000000000000000000..33a97738839640db2c44f5f90e9d20eb89c08590 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02191.java @@ -0,0 +1,166 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02191") +public class BenchmarkTest02191 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02191"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02192.java b/OWASP DATASET/BenchmarkTest02192.java new file mode 100644 index 0000000000000000000000000000000000000000..8a5b1e5beba1d5870c0991b4a0f13a5b347a8a2b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02192.java @@ -0,0 +1,174 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02192") +public class BenchmarkTest02192 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02192"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02193.java b/OWASP DATASET/BenchmarkTest02193.java new file mode 100644 index 0000000000000000000000000000000000000000..72a5551228c6e0fed02b1eb9328d753e40d06e75 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02193.java @@ -0,0 +1,183 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02193") +public class BenchmarkTest02193 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02193"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02194.java b/OWASP DATASET/BenchmarkTest02194.java new file mode 100644 index 0000000000000000000000000000000000000000..9ddca94c22b4c66c1f623696a4640dc7cd1bf11b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02194.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02194") +public class BenchmarkTest02194 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02194"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02195.java b/OWASP DATASET/BenchmarkTest02195.java new file mode 100644 index 0000000000000000000000000000000000000000..01595fc13c52583b52f2197b9ded2045910ad1f8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02195.java @@ -0,0 +1,135 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02195") +public class BenchmarkTest02195 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02195"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02196.java b/OWASP DATASET/BenchmarkTest02196.java new file mode 100644 index 0000000000000000000000000000000000000000..de20630555bebd2cafb44db591ccd4ec0dc71637 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02196.java @@ -0,0 +1,128 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest02196") +public class BenchmarkTest02196 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02196"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + javax.naming.directory.DirContext ctx = ads.getDirContext(); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person)(uid=" + bar + "))"; + // System.out.println("Filter " + filter); + boolean found = false; + javax.naming.NamingEnumeration results = + ctx.search(base, filter, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02197.java b/OWASP DATASET/BenchmarkTest02197.java new file mode 100644 index 0000000000000000000000000000000000000000..8906b740d725b1e81b688ad80ee3c858b987da23 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02197.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02197") +public class BenchmarkTest02197 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02197"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map35951 = new java.util.HashMap(); + map35951.put("keyA-35951", "a-Value"); // put some stuff in the collection + map35951.put("keyB-35951", param); // put it in a collection + map35951.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map35951.get("keyB-35951"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02198.java b/OWASP DATASET/BenchmarkTest02198.java new file mode 100644 index 0000000000000000000000000000000000000000..a8a861b1c97aec0edaba3dc91a924bcf84609653 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02198.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02198") +public class BenchmarkTest02198 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02198"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + java.io.File fileTarget = + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR, bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02199.java b/OWASP DATASET/BenchmarkTest02199.java new file mode 100644 index 0000000000000000000000000000000000000000..50acae25ed9a83efab57c48e533005ef1770d376 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02199.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02199") +public class BenchmarkTest02199 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02199"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + java.io.File fileTarget = new java.io.File(bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02200.java b/OWASP DATASET/BenchmarkTest02200.java new file mode 100644 index 0000000000000000000000000000000000000000..6c236bb09ddb7f093b04058bd1135b51e3744dc3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02200.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02200") +public class BenchmarkTest02200 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02200"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + java.io.File fileTarget = new java.io.File(bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02201.java b/OWASP DATASET/BenchmarkTest02201.java new file mode 100644 index 0000000000000000000000000000000000000000..74ab7fdf5537e54745b1dd8beb8377f8408ed6b9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02201.java @@ -0,0 +1,118 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02201") +public class BenchmarkTest02201 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02201"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(new java.io.File(fileName)); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting FileInputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02202.java b/OWASP DATASET/BenchmarkTest02202.java new file mode 100644 index 0000000000000000000000000000000000000000..27047a2402d144b8382409f34414d7ad9327c751 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02202.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02202") +public class BenchmarkTest02202 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02202"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName), false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02203.java b/OWASP DATASET/BenchmarkTest02203.java new file mode 100644 index 0000000000000000000000000000000000000000..8de8cd1df0484c62134134b73ff42cd67fa84648 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02203.java @@ -0,0 +1,107 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02203") +public class BenchmarkTest02203 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02203"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName)); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a31470 = param; // assign + StringBuilder b31470 = new StringBuilder(a31470); // stick in stringbuilder + b31470.append(" SafeStuff"); // append some safe content + b31470.replace( + b31470.length() - "Chars".length(), + b31470.length(), + "Chars"); // replace some of the end content + java.util.HashMap map31470 = new java.util.HashMap(); + map31470.put("key31470", b31470.toString()); // put in a collection + String c31470 = (String) map31470.get("key31470"); // get it back out + String d31470 = c31470.substring(0, c31470.length() - 1); // extract most of it + String e31470 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d31470.getBytes()))); // B64 encode and decode it + String f31470 = e31470.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g31470 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g31470); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02204.java b/OWASP DATASET/BenchmarkTest02204.java new file mode 100644 index 0000000000000000000000000000000000000000..9ed94c10c5f53569f1635311216778eb33adb31f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02204.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02204") +public class BenchmarkTest02204 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02204"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + try ( + // Create the file first so the test won't throw an exception if it doesn't exist. + // Note: Don't actually do this because this method signature could cause a tool to find + // THIS file constructor + // as a vuln, rather than the File signature we are trying to actually test. + // If necessary, just run the benchmark twice. The 1st run should create all the necessary + // files. + // new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar).createNewFile(); + + java.io.FileOutputStream fos = + new java.io.FileOutputStream(new java.io.FileInputStream(fileName).getFD()); ) { + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02205.java b/OWASP DATASET/BenchmarkTest02205.java new file mode 100644 index 0000000000000000000000000000000000000000..220bc9b97f0ef2fbd56bb57583bb5926dc24b354 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02205.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02205") +public class BenchmarkTest02205 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02205"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02206.java b/OWASP DATASET/BenchmarkTest02206.java new file mode 100644 index 0000000000000000000000000000000000000000..0dacb5bbfb20ccc6fa0a744e42feb0df246c8659 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02206.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02206") +public class BenchmarkTest02206 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02206"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + java.io.InputStream is = null; + + try { + java.nio.file.Path path = java.nio.file.Paths.get(fileName); + is = java.nio.file.Files.newInputStream(path, java.nio.file.StandardOpenOption.READ); + byte[] b = new byte[1000]; + int size = is.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + is.close(); + } catch (Exception e) { + System.out.println("Couldn't open InputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting InputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (is != null) { + try { + is.close(); + is = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02207.java b/OWASP DATASET/BenchmarkTest02207.java new file mode 100644 index 0000000000000000000000000000000000000000..90bf5f29cc87d907611180b69b2b008ee71b4907 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02207.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02207") +public class BenchmarkTest02207 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02207"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + java.io.InputStream is = null; + + try { + java.nio.file.Path path = java.nio.file.Paths.get(fileName); + is = java.nio.file.Files.newInputStream(path, java.nio.file.StandardOpenOption.READ); + byte[] b = new byte[1000]; + int size = is.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + is.close(); + } catch (Exception e) { + System.out.println("Couldn't open InputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting InputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (is != null) { + try { + is.close(); + is = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02208.java b/OWASP DATASET/BenchmarkTest02208.java new file mode 100644 index 0000000000000000000000000000000000000000..525ff4177c3b13ddeef2f140090d2070cdbca6b2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02208.java @@ -0,0 +1,131 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest02208") +public class BenchmarkTest02208 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02208"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + bar + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + + javax.naming.directory.DirContext ctx = ads.getDirContext(); + javax.naming.directory.InitialDirContext idc = + (javax.naming.directory.InitialDirContext) ctx; + boolean found = false; + javax.naming.NamingEnumeration results = + idc.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02209.java b/OWASP DATASET/BenchmarkTest02209.java new file mode 100644 index 0000000000000000000000000000000000000000..04857c88662ab2bf335d52d95c33da96d58693f0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02209.java @@ -0,0 +1,128 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02209") +public class BenchmarkTest02209 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02209"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + double value = java.lang.Math.random(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Doug"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + response.getWriter().println("Weak Randomness Test java.lang.Math.random() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02210.java b/OWASP DATASET/BenchmarkTest02210.java new file mode 100644 index 0000000000000000000000000000000000000000..36ac24eeba6530fd445016eb96dfd7f3115acacd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02210.java @@ -0,0 +1,122 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02210") +public class BenchmarkTest02210 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02210"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("sha-384", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("sha-384", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02211.java b/OWASP DATASET/BenchmarkTest02211.java new file mode 100644 index 0000000000000000000000000000000000000000..3ffcfafcee0a4067e434e8925a8c9153542a8141 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02211.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02211") +public class BenchmarkTest02211 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02211"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02212.java b/OWASP DATASET/BenchmarkTest02212.java new file mode 100644 index 0000000000000000000000000000000000000000..1f771b10ef8f24ceb220c1f9e03d504081b365a8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02212.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02212") +public class BenchmarkTest02212 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02212"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02213.java b/OWASP DATASET/BenchmarkTest02213.java new file mode 100644 index 0000000000000000000000000000000000000000..77daec99cc9617a17bab0588041cc24fedc35285 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02213.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02213") +public class BenchmarkTest02213 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02213"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02214.java b/OWASP DATASET/BenchmarkTest02214.java new file mode 100644 index 0000000000000000000000000000000000000000..6f73bc8dc9ba7e3d1ed18d00dc2d85c3a9efbcda --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02214.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02214") +public class BenchmarkTest02214 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02214"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = + java.security.MessageDigest.getInstance("SHA-512", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02215.java b/OWASP DATASET/BenchmarkTest02215.java new file mode 100644 index 0000000000000000000000000000000000000000..5a18cf9adb8e01a98c0b71325d9d0317f96c8d59 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02215.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02215") +public class BenchmarkTest02215 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02215"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = + java.security.MessageDigest.getInstance("SHA-512", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02216.java b/OWASP DATASET/BenchmarkTest02216.java new file mode 100644 index 0000000000000000000000000000000000000000..70651e8d1d85c5a0d67f4a96876970827792cb5a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02216.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02216") +public class BenchmarkTest02216 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02216"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = + java.security.MessageDigest.getInstance("SHA-512", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02217.java b/OWASP DATASET/BenchmarkTest02217.java new file mode 100644 index 0000000000000000000000000000000000000000..883c554f8d597699b2f3c5699c2932375f1bb303 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02217.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02217") +public class BenchmarkTest02217 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02217"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02218.java b/OWASP DATASET/BenchmarkTest02218.java new file mode 100644 index 0000000000000000000000000000000000000000..e8cc9e4fd5f880ba04de104be750e8c0419e1873 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02218.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02218") +public class BenchmarkTest02218 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02218"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-256"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02219.java b/OWASP DATASET/BenchmarkTest02219.java new file mode 100644 index 0000000000000000000000000000000000000000..4841241de2e5df508bfeea67ba85863c31c5745e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02219.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02219") +public class BenchmarkTest02219 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02219"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02220.java b/OWASP DATASET/BenchmarkTest02220.java new file mode 100644 index 0000000000000000000000000000000000000000..6a44fec93b961fe5f2e895c20221eb7492fa9813 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02220.java @@ -0,0 +1,133 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02220") +public class BenchmarkTest02220 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02220"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a19972 = param; // assign + StringBuilder b19972 = new StringBuilder(a19972); // stick in stringbuilder + b19972.append(" SafeStuff"); // append some safe content + b19972.replace( + b19972.length() - "Chars".length(), + b19972.length(), + "Chars"); // replace some of the end content + java.util.HashMap map19972 = new java.util.HashMap(); + map19972.put("key19972", b19972.toString()); // put in a collection + String c19972 = (String) map19972.get("key19972"); // get it back out + String d19972 = c19972.substring(0, c19972.length() - 1); // extract most of it + String e19972 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d19972.getBytes()))); // B64 encode and decode it + String f19972 = e19972.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f19972); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02221.java b/OWASP DATASET/BenchmarkTest02221.java new file mode 100644 index 0000000000000000000000000000000000000000..a3126d4620a2a4752cf784c4d8b24bdec4e19703 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02221.java @@ -0,0 +1,71 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02221") +public class BenchmarkTest02221 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02221"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + java.io.PrintWriter out = response.getWriter(); + out.write("\n\n\n

"); + out.format(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + out.write("\n

\n\n"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz71523 = new StringBuilder(param); + bar = sbxyz71523.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02222.java b/OWASP DATASET/BenchmarkTest02222.java new file mode 100644 index 0000000000000000000000000000000000000000..cfdd91c768d91adc776595a31983a488e612aa07 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02222.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02222") +public class BenchmarkTest02222 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02222"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(java.util.Locale.US, bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02223.java b/OWASP DATASET/BenchmarkTest02223.java new file mode 100644 index 0000000000000000000000000000000000000000..29b691e1e827440385f81d1db69bc10ff9267e20 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02223.java @@ -0,0 +1,65 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02223") +public class BenchmarkTest02223 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02223"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().format("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz60073 = new StringBuilder(param); + String bar = sbxyz60073.append("_SafeStuff").toString(); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02224.java b/OWASP DATASET/BenchmarkTest02224.java new file mode 100644 index 0000000000000000000000000000000000000000..a54b52255ae15df5ce7ddee97a27e4d46ac7696e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02224.java @@ -0,0 +1,69 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02224") +public class BenchmarkTest02224 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02224"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().format("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02225.java b/OWASP DATASET/BenchmarkTest02225.java new file mode 100644 index 0000000000000000000000000000000000000000..a47a2df5371bece3ab262e3c89a8cb4578677e1f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02225.java @@ -0,0 +1,69 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02225") +public class BenchmarkTest02225 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02225"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map73885 = new java.util.HashMap(); + map73885.put("keyA-73885", "a-Value"); // put some stuff in the collection + map73885.put("keyB-73885", param); // put it in a collection + map73885.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map73885.get("keyB-73885"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02226.java b/OWASP DATASET/BenchmarkTest02226.java new file mode 100644 index 0000000000000000000000000000000000000000..91d6561f064995184a7b9afe3a192f314057c05f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02226.java @@ -0,0 +1,68 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02226") +public class BenchmarkTest02226 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02226"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar.toCharArray()); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02227.java b/OWASP DATASET/BenchmarkTest02227.java new file mode 100644 index 0000000000000000000000000000000000000000..4f3348255f5e70875e099cece7e60d240e8123ad --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02227.java @@ -0,0 +1,64 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02227") +public class BenchmarkTest02227 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02227"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar.toCharArray()); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz39187 = new StringBuilder(param); + String bar = sbxyz39187.append("_SafeStuff").toString(); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02228.java b/OWASP DATASET/BenchmarkTest02228.java new file mode 100644 index 0000000000000000000000000000000000000000..3343595760561707f5a6a7b69d1543a1523eda83 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02228.java @@ -0,0 +1,64 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02228") +public class BenchmarkTest02228 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02228"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz60124 = new StringBuilder(param); + String bar = sbxyz60124.append("_SafeStuff").toString(); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02229.java b/OWASP DATASET/BenchmarkTest02229.java new file mode 100644 index 0000000000000000000000000000000000000000..378334e7ccf1926837a9790e19fbdae4f83638f0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02229.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02229") +public class BenchmarkTest02229 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02229"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map26903 = new java.util.HashMap(); + map26903.put("keyA-26903", "a_Value"); // put some stuff in the collection + map26903.put("keyB-26903", param); // put it in a collection + map26903.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map26903.get("keyB-26903"); // get it back out + bar = (String) map26903.get("keyA-26903"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02230.java b/OWASP DATASET/BenchmarkTest02230.java new file mode 100644 index 0000000000000000000000000000000000000000..fbf7949d3f9874fbe2b4e61d34dd0ba90980b4a8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02230.java @@ -0,0 +1,68 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02230") +public class BenchmarkTest02230 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02230"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz51189 = new StringBuilder(param); + bar = sbxyz51189.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02231.java b/OWASP DATASET/BenchmarkTest02231.java new file mode 100644 index 0000000000000000000000000000000000000000..1f4f709ce865c7727715db2ad470b20ba60f52ca --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02231.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02231") +public class BenchmarkTest02231 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02231"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {bar, "b"}; + response.getWriter().printf("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a60610 = param; // assign + StringBuilder b60610 = new StringBuilder(a60610); // stick in stringbuilder + b60610.append(" SafeStuff"); // append some safe content + b60610.replace( + b60610.length() - "Chars".length(), + b60610.length(), + "Chars"); // replace some of the end content + java.util.HashMap map60610 = new java.util.HashMap(); + map60610.put("key60610", b60610.toString()); // put in a collection + String c60610 = (String) map60610.get("key60610"); // get it back out + String d60610 = c60610.substring(0, c60610.length() - 1); // extract most of it + String e60610 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d60610.getBytes()))); // B64 encode and decode it + String f60610 = e60610.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g60610 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g60610); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02232.java b/OWASP DATASET/BenchmarkTest02232.java new file mode 100644 index 0000000000000000000000000000000000000000..889690033ee4cc895dd7a3b6bb451b72447f8a78 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02232.java @@ -0,0 +1,64 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02232") +public class BenchmarkTest02232 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02232"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02233.java b/OWASP DATASET/BenchmarkTest02233.java new file mode 100644 index 0000000000000000000000000000000000000000..4b418c452ed1fe5b64559cb84c4f8eab8b927483 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02233.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02233") +public class BenchmarkTest02233 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02233"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02234.java b/OWASP DATASET/BenchmarkTest02234.java new file mode 100644 index 0000000000000000000000000000000000000000..51cfa7074a951bf8b87a5785b9d3e18cb59a9e19 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02234.java @@ -0,0 +1,65 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02234") +public class BenchmarkTest02234 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02234"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz86132 = new StringBuilder(param); + String bar = sbxyz86132.append("_SafeStuff").toString(); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02235.java b/OWASP DATASET/BenchmarkTest02235.java new file mode 100644 index 0000000000000000000000000000000000000000..afd2a82ebc3510f8425cc2285957efcd39de24bb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02235.java @@ -0,0 +1,68 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02235") +public class BenchmarkTest02235 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02235"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar.toCharArray()); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02236.java b/OWASP DATASET/BenchmarkTest02236.java new file mode 100644 index 0000000000000000000000000000000000000000..2c01bb9cfbea4ddcf5cd55bd2cc78cfbb63c23fd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02236.java @@ -0,0 +1,68 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02236") +public class BenchmarkTest02236 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02236"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02237.java b/OWASP DATASET/BenchmarkTest02237.java new file mode 100644 index 0000000000000000000000000000000000000000..1f4534030541673747cfd2ae34cb7350c2be0239 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02237.java @@ -0,0 +1,63 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02237") +public class BenchmarkTest02237 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02237"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02238.java b/OWASP DATASET/BenchmarkTest02238.java new file mode 100644 index 0000000000000000000000000000000000000000..e5fd6cc5ef1070e16ea90c6f1beac5493d3125de --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02238.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02238") +public class BenchmarkTest02238 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02238"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a16227 = param; // assign + StringBuilder b16227 = new StringBuilder(a16227); // stick in stringbuilder + b16227.append(" SafeStuff"); // append some safe content + b16227.replace( + b16227.length() - "Chars".length(), + b16227.length(), + "Chars"); // replace some of the end content + java.util.HashMap map16227 = new java.util.HashMap(); + map16227.put("key16227", b16227.toString()); // put in a collection + String c16227 = (String) map16227.get("key16227"); // get it back out + String d16227 = c16227.substring(0, c16227.length() - 1); // extract most of it + String e16227 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d16227.getBytes()))); // B64 encode and decode it + String f16227 = e16227.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g16227 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g16227); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02239.java b/OWASP DATASET/BenchmarkTest02239.java new file mode 100644 index 0000000000000000000000000000000000000000..e3ea0a13626d2504969a90425257268314e2bbe4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02239.java @@ -0,0 +1,73 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02239") +public class BenchmarkTest02239 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02239"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar.toCharArray()); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02240.java b/OWASP DATASET/BenchmarkTest02240.java new file mode 100644 index 0000000000000000000000000000000000000000..6fd426736b18db77ff91dbf9b797611ffb77604d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02240.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02240") +public class BenchmarkTest02240 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02240"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02241.java b/OWASP DATASET/BenchmarkTest02241.java new file mode 100644 index 0000000000000000000000000000000000000000..a8c3da812d0091e5edd1b4a4d58d2702b7430ca6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02241.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02241") +public class BenchmarkTest02241 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02241"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02242.java b/OWASP DATASET/BenchmarkTest02242.java new file mode 100644 index 0000000000000000000000000000000000000000..00fc1f8ea8aeb834864b86d5543698803d690cb2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02242.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02242") +public class BenchmarkTest02242 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02242"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(); + + pb.command(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a91595 = param; // assign + StringBuilder b91595 = new StringBuilder(a91595); // stick in stringbuilder + b91595.append(" SafeStuff"); // append some safe content + b91595.replace( + b91595.length() - "Chars".length(), + b91595.length(), + "Chars"); // replace some of the end content + java.util.HashMap map91595 = new java.util.HashMap(); + map91595.put("key91595", b91595.toString()); // put in a collection + String c91595 = (String) map91595.get("key91595"); // get it back out + String d91595 = c91595.substring(0, c91595.length() - 1); // extract most of it + String e91595 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d91595.getBytes()))); // B64 encode and decode it + String f91595 = e91595.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g91595 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g91595); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02243.java b/OWASP DATASET/BenchmarkTest02243.java new file mode 100644 index 0000000000000000000000000000000000000000..40c8c4f56d54d79cfcfd20b83a47e415c93a6168 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02243.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02243") +public class BenchmarkTest02243 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02243"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map19941 = new java.util.HashMap(); + map19941.put("keyA-19941", "a-Value"); // put some stuff in the collection + map19941.put("keyB-19941", param); // put it in a collection + map19941.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map19941.get("keyB-19941"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02244.java b/OWASP DATASET/BenchmarkTest02244.java new file mode 100644 index 0000000000000000000000000000000000000000..6cb12a71ac80a71c46113e39fee7a6d8f6ab3aec --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02244.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02244") +public class BenchmarkTest02244 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02244"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02245.java b/OWASP DATASET/BenchmarkTest02245.java new file mode 100644 index 0000000000000000000000000000000000000000..0d8dd4aaf590eaa2d58cb661c0a62c6c245a20ab --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02245.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02245") +public class BenchmarkTest02245 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02245"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + int randNumber = new java.util.Random().nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "Inga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt(int) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02246.java b/OWASP DATASET/BenchmarkTest02246.java new file mode 100644 index 0000000000000000000000000000000000000000..e5af1bea0b2372288c2ecb9d501e551cf004eb9e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02246.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02246") +public class BenchmarkTest02246 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02246"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + int randNumber = new java.util.Random().nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "Inga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt(int) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map19712 = new java.util.HashMap(); + map19712.put("keyA-19712", "a-Value"); // put some stuff in the collection + map19712.put("keyB-19712", param); // put it in a collection + map19712.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map19712.get("keyB-19712"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02247.java b/OWASP DATASET/BenchmarkTest02247.java new file mode 100644 index 0000000000000000000000000000000000000000..3d83683a62ee8a49bfbb3060b2a5c6391468e561 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02247.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest02247") +public class BenchmarkTest02247 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02247"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02248.java b/OWASP DATASET/BenchmarkTest02248.java new file mode 100644 index 0000000000000000000000000000000000000000..f88028346c55610b291bb0b4bbdf43c55c51b8a1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02248.java @@ -0,0 +1,90 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest02248") +public class BenchmarkTest02248 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02248"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02249.java b/OWASP DATASET/BenchmarkTest02249.java new file mode 100644 index 0000000000000000000000000000000000000000..5c16c13b0fa7cfa58769747e118037d1f3f503d9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02249.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02249") +public class BenchmarkTest02249 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02249"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02250.java b/OWASP DATASET/BenchmarkTest02250.java new file mode 100644 index 0000000000000000000000000000000000000000..e947d603241789c2866da1fc2a8ae025fc1ecb17 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02250.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02250") +public class BenchmarkTest02250 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02250"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map94176 = new java.util.HashMap(); + map94176.put("keyA-94176", "a-Value"); // put some stuff in the collection + map94176.put("keyB-94176", param); // put it in a collection + map94176.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map94176.get("keyB-94176"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02251.java b/OWASP DATASET/BenchmarkTest02251.java new file mode 100644 index 0000000000000000000000000000000000000000..3dfcbd51e745cbc154d98b92a1ae73ad649abe4f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02251.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02251") +public class BenchmarkTest02251 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02251"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ping -c1 "); + args = new String[] {a1, a2, cmd + bar}; + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02252.java b/OWASP DATASET/BenchmarkTest02252.java new file mode 100644 index 0000000000000000000000000000000000000000..46abd6c4b3e1a1aca5dc2435ea9eee219e5e64c0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02252.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02252") +public class BenchmarkTest02252 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02252"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02253.java b/OWASP DATASET/BenchmarkTest02253.java new file mode 100644 index 0000000000000000000000000000000000000000..af4e1adea3ee8ec9d0dddb192fafe51c2660f2df --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02253.java @@ -0,0 +1,111 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02253") +public class BenchmarkTest02253 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02253"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02254.java b/OWASP DATASET/BenchmarkTest02254.java new file mode 100644 index 0000000000000000000000000000000000000000..31b1eaeb60459f787cd8d62211d3f716dca89435 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02254.java @@ -0,0 +1,131 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02254") +public class BenchmarkTest02254 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02254"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + getNextNumber(numGen, randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeBystander"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + void getNextNumber(java.util.Random generator, byte[] barray) { + generator.nextBytes(barray); + } + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02255.java b/OWASP DATASET/BenchmarkTest02255.java new file mode 100644 index 0000000000000000000000000000000000000000..660600aca474fdfbe92c912784d13761e2d887a1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02255.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02255") +public class BenchmarkTest02255 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02255"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02256.java b/OWASP DATASET/BenchmarkTest02256.java new file mode 100644 index 0000000000000000000000000000000000000000..df1ba88e2d357d7ef3583284f66487a4e7bca5d8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02256.java @@ -0,0 +1,122 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02256") +public class BenchmarkTest02256 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02256"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02257.java b/OWASP DATASET/BenchmarkTest02257.java new file mode 100644 index 0000000000000000000000000000000000000000..0a6049a61929b5152b777e7bfac2a2fff9bede55 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02257.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02257") +public class BenchmarkTest02257 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02257"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02258.java b/OWASP DATASET/BenchmarkTest02258.java new file mode 100644 index 0000000000000000000000000000000000000000..1fa609c60ce4bb908621ae3ca1c8d94ee2ab327f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02258.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02258") +public class BenchmarkTest02258 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02258"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + double rand = getNextNumber(numGen); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonatella"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + double getNextNumber(java.util.Random generator) { + return generator.nextDouble(); + } + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02259.java b/OWASP DATASET/BenchmarkTest02259.java new file mode 100644 index 0000000000000000000000000000000000000000..19a160492685a57ae5817a7fe30537fb05897224 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02259.java @@ -0,0 +1,122 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02259") +public class BenchmarkTest02259 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02259"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02260.java b/OWASP DATASET/BenchmarkTest02260.java new file mode 100644 index 0000000000000000000000000000000000000000..c8c5efeea5dd2d6f72a7321407d3dd1627a0a4fb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02260.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02260") +public class BenchmarkTest02260 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02260"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + try { + int r = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "SafeIngrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02261.java b/OWASP DATASET/BenchmarkTest02261.java new file mode 100644 index 0000000000000000000000000000000000000000..878ef493c3eb49a035164d0066d44fa449604e8a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02261.java @@ -0,0 +1,69 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest02261") +public class BenchmarkTest02261 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02261"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String^,java.lang.Object) + request.getSession().putValue(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: 10340 saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02262.java b/OWASP DATASET/BenchmarkTest02262.java new file mode 100644 index 0000000000000000000000000000000000000000..81b2be77bd363d0c15b2d3f0386767f99a2c3f76 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02262.java @@ -0,0 +1,69 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest02262") +public class BenchmarkTest02262 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02262"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02263.java b/OWASP DATASET/BenchmarkTest02263.java new file mode 100644 index 0000000000000000000000000000000000000000..3601a35df396044611797be9b526613e66ad9d29 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02263.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest02263") +public class BenchmarkTest02263 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02263"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String^,java.lang.Object) + request.getSession().setAttribute(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: '10340' saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02264.java b/OWASP DATASET/BenchmarkTest02264.java new file mode 100644 index 0000000000000000000000000000000000000000..ae2d93b9a2f7a4a7f19bcb05f896c0f7d70f4788 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02264.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02264") +public class BenchmarkTest02264 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02264"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = connection.prepareCall(sql); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02265.java b/OWASP DATASET/BenchmarkTest02265.java new file mode 100644 index 0000000000000000000000000000000000000000..01b61fe0013a3be4cc9d2df0540f23579b2cb460 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02265.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02265") +public class BenchmarkTest02265 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02265"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02266.java b/OWASP DATASET/BenchmarkTest02266.java new file mode 100644 index 0000000000000000000000000000000000000000..e43009b44378f47a6a92b5cfd3fe11d9d1fb79a2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02266.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02266") +public class BenchmarkTest02266 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02266"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02267.java b/OWASP DATASET/BenchmarkTest02267.java new file mode 100644 index 0000000000000000000000000000000000000000..5f87994cb96f512e70ba3c33c551228d47737986 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02267.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02267") +public class BenchmarkTest02267 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02267"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = connection.prepareStatement(sql); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02268.java b/OWASP DATASET/BenchmarkTest02268.java new file mode 100644 index 0000000000000000000000000000000000000000..515184a32690f01782c5f0270d5de04df564b3cb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02268.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02268") +public class BenchmarkTest02268 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02268"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map95440 = new java.util.HashMap(); + map95440.put("keyA-95440", "a_Value"); // put some stuff in the collection + map95440.put("keyB-95440", param); // put it in a collection + map95440.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map95440.get("keyB-95440"); // get it back out + bar = (String) map95440.get("keyA-95440"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02269.java b/OWASP DATASET/BenchmarkTest02269.java new file mode 100644 index 0000000000000000000000000000000000000000..b90b184768dcfb10ec661dd7afa4a5babe4cd068 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02269.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02269") +public class BenchmarkTest02269 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02269"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02270.java b/OWASP DATASET/BenchmarkTest02270.java new file mode 100644 index 0000000000000000000000000000000000000000..d11e5ede3e7ff2a8a4b597959778d30d37f0295a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02270.java @@ -0,0 +1,100 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02270") +public class BenchmarkTest02270 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02270"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02271.java b/OWASP DATASET/BenchmarkTest02271.java new file mode 100644 index 0000000000000000000000000000000000000000..1b90bd2cc9d587f786de6493787b6853ad383e79 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02271.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02271") +public class BenchmarkTest02271 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02271"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, new int[] {1, 2}); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02272.java b/OWASP DATASET/BenchmarkTest02272.java new file mode 100644 index 0000000000000000000000000000000000000000..68c4bfaf57a928b43675fb7242e27faac9c205d8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02272.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02272") +public class BenchmarkTest02272 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02272"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + // System.out.println("no results for query: " + sql + " because the Spring batchUpdate + // method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02273.java b/OWASP DATASET/BenchmarkTest02273.java new file mode 100644 index 0000000000000000000000000000000000000000..609d991b973f33c11cdbbf49484fac5d85f1fc23 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02273.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02273") +public class BenchmarkTest02273 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02273"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + // System.out.println("no results for query: " + sql + " because the Spring batchUpdate + // method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02274.java b/OWASP DATASET/BenchmarkTest02274.java new file mode 100644 index 0000000000000000000000000000000000000000..4c346dbd5bf004e6c024b8b86af4a211211ab5e2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02274.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02274") +public class BenchmarkTest02274 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02274"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.query( + sql, + new org.springframework.jdbc.core.RowMapper() { + @Override + public String mapRow(java.sql.ResultSet rs, int rowNum) + throws java.sql.SQLException { + try { + return rs.getString("USERNAME"); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper + .hideSQLErrors) { + return "Error processing query."; + } else throw e; + } + } + }); + response.getWriter().println("Your results are: "); + + for (String s : results) { + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(s) + "
"); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02275.java b/OWASP DATASET/BenchmarkTest02275.java new file mode 100644 index 0000000000000000000000000000000000000000..d9c2334a7c44fad9b84a45cbd8b5cb41e1bcab63 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02275.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-04/BenchmarkTest02275") +public class BenchmarkTest02275 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02275"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // int results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForInt(sql); + Integer results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Integer.class); + response.getWriter().println("Your results are: " + results); + // System.out.println("Your results are: " + results); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02276.java b/OWASP DATASET/BenchmarkTest02276.java new file mode 100644 index 0000000000000000000000000000000000000000..a36ec164faaf0ebfc45b30f59151749d9177b1a8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02276.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02276") +public class BenchmarkTest02276 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02276"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // int results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForInt(sql); + Integer results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Integer.class); + response.getWriter().println("Your results are: " + results); + // System.out.println("Your results are: " + results); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02277.java b/OWASP DATASET/BenchmarkTest02277.java new file mode 100644 index 0000000000000000000000000000000000000000..b67c1299896da9e0e54d5cd563af51e95dd7251e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02277.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02277") +public class BenchmarkTest02277 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02277"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List> list = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForList(sql); + response.getWriter().println("Your results are:
"); + + // System.out.println("Your results are"); + + for (Object o : list) { + response.getWriter() + .println( + org.owasp.esapi.ESAPI.encoder().encodeForHTML(o.toString()) + + "
"); + // System.out.println(o.toString()); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02278.java b/OWASP DATASET/BenchmarkTest02278.java new file mode 100644 index 0000000000000000000000000000000000000000..1151848a297235d72694054c5b6f6a9e3ce57441 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02278.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02278") +public class BenchmarkTest02278 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02278"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // Long results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForLong(sql); + Long results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Long.class); + response.getWriter().println("Your results are: " + String.valueOf(results)); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map96698 = new java.util.HashMap(); + map96698.put("keyA-96698", "a_Value"); // put some stuff in the collection + map96698.put("keyB-96698", param); // put it in a collection + map96698.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map96698.get("keyB-96698"); // get it back out + bar = (String) map96698.get("keyA-96698"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02279.java b/OWASP DATASET/BenchmarkTest02279.java new file mode 100644 index 0000000000000000000000000000000000000000..e2d980e42d5e6b068a3921c59dfcb1a435763e44 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02279.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02279") +public class BenchmarkTest02279 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02279"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // Long results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForLong(sql); + Long results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Long.class); + response.getWriter().println("Your results are: " + String.valueOf(results)); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02280.java b/OWASP DATASET/BenchmarkTest02280.java new file mode 100644 index 0000000000000000000000000000000000000000..1fbe5c6fb8f1fe0d9258be1a383ba713860c398e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02280.java @@ -0,0 +1,98 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02280") +public class BenchmarkTest02280 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02280"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // Long results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForLong(sql); + Long results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Long.class); + response.getWriter().println("Your results are: " + String.valueOf(results)); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02281.java b/OWASP DATASET/BenchmarkTest02281.java new file mode 100644 index 0000000000000000000000000000000000000000..7c5807700b1ad63f495970aa6df4a4c4ca96dd23 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02281.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02281") +public class BenchmarkTest02281 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02281"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String sql = + "SELECT TOP 1 userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.Map results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForMap(sql); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(results.toString())); + // System.out.println(results.toString()); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02282.java b/OWASP DATASET/BenchmarkTest02282.java new file mode 100644 index 0000000000000000000000000000000000000000..e1feed1ebfa176f930bfca08182724104f896aa8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02282.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02282") +public class BenchmarkTest02282 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02282"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02283.java b/OWASP DATASET/BenchmarkTest02283.java new file mode 100644 index 0000000000000000000000000000000000000000..706b0737042164faac323202d63718ad2168e656 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02283.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02283") +public class BenchmarkTest02283 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02283"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02284.java b/OWASP DATASET/BenchmarkTest02284.java new file mode 100644 index 0000000000000000000000000000000000000000..780d7601916ec62af1fd42f65877f713d8282e07 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02284.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02284") +public class BenchmarkTest02284 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02284"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new String[] {"username", "password"}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02285.java b/OWASP DATASET/BenchmarkTest02285.java new file mode 100644 index 0000000000000000000000000000000000000000..5526d425eb8b7aea6751a50b4930e9bf83466252 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02285.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02285") +public class BenchmarkTest02285 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02285"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new String[] {"username", "password"}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02286.java b/OWASP DATASET/BenchmarkTest02286.java new file mode 100644 index 0000000000000000000000000000000000000000..beb83e124a563a55c8217df98945eaf299b64f2a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02286.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02286") +public class BenchmarkTest02286 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02286"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02287.java b/OWASP DATASET/BenchmarkTest02287.java new file mode 100644 index 0000000000000000000000000000000000000000..a32f27fbaefe83271b3ab649b4b5d7065c7f3a3d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02287.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02287") +public class BenchmarkTest02287 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02287"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new String[] {"USERNAME", "PASSWORD"}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02288.java b/OWASP DATASET/BenchmarkTest02288.java new file mode 100644 index 0000000000000000000000000000000000000000..2a71006a55b492c2cdee753a2ee4217ac768194a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02288.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02288") +public class BenchmarkTest02288 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + java.util.Map map = request.getParameterMap(); + String param = ""; + if (!map.isEmpty()) { + String[] values = map.get("BenchmarkTest02288"); + if (values != null) param = values[0]; + } + + String bar = doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new String[] {"USERNAME", "PASSWORD"}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02289.java b/OWASP DATASET/BenchmarkTest02289.java new file mode 100644 index 0000000000000000000000000000000000000000..5cc4e2ad3172ed71ca0a2bfe2ab03c5f4d93ba6a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02289.java @@ -0,0 +1,171 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02289") +public class BenchmarkTest02289 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02289")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02290.java b/OWASP DATASET/BenchmarkTest02290.java new file mode 100644 index 0000000000000000000000000000000000000000..e14dfb145c8773b5a67da19b8b90ff62f7ed1d94 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02290.java @@ -0,0 +1,181 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02290") +public class BenchmarkTest02290 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02290")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02291.java b/OWASP DATASET/BenchmarkTest02291.java new file mode 100644 index 0000000000000000000000000000000000000000..29b5c42fae95a5a423097d1756cf2b5d8c00ebc6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02291.java @@ -0,0 +1,195 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02291") +public class BenchmarkTest02291 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02291")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a10347 = param; // assign + StringBuilder b10347 = new StringBuilder(a10347); // stick in stringbuilder + b10347.append(" SafeStuff"); // append some safe content + b10347.replace( + b10347.length() - "Chars".length(), + b10347.length(), + "Chars"); // replace some of the end content + java.util.HashMap map10347 = new java.util.HashMap(); + map10347.put("key10347", b10347.toString()); // put in a collection + String c10347 = (String) map10347.get("key10347"); // get it back out + String d10347 = c10347.substring(0, c10347.length() - 1); // extract most of it + String e10347 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d10347.getBytes()))); // B64 encode and decode it + String f10347 = e10347.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g10347 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g10347); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02292.java b/OWASP DATASET/BenchmarkTest02292.java new file mode 100644 index 0000000000000000000000000000000000000000..1af53015f7d52254e08217d6839f30a6abc15a3c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02292.java @@ -0,0 +1,174 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02292") +public class BenchmarkTest02292 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02292")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02293.java b/OWASP DATASET/BenchmarkTest02293.java new file mode 100644 index 0000000000000000000000000000000000000000..2e60ca00ebeb3467b33492714ccce9277ff3cfe6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02293.java @@ -0,0 +1,160 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02293") +public class BenchmarkTest02293 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02293")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a87246 = param; // assign + StringBuilder b87246 = new StringBuilder(a87246); // stick in stringbuilder + b87246.append(" SafeStuff"); // append some safe content + b87246.replace( + b87246.length() - "Chars".length(), + b87246.length(), + "Chars"); // replace some of the end content + java.util.HashMap map87246 = new java.util.HashMap(); + map87246.put("key87246", b87246.toString()); // put in a collection + String c87246 = (String) map87246.get("key87246"); // get it back out + String d87246 = c87246.substring(0, c87246.length() - 1); // extract most of it + String e87246 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d87246.getBytes()))); // B64 encode and decode it + String f87246 = e87246.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f87246); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02294.java b/OWASP DATASET/BenchmarkTest02294.java new file mode 100644 index 0000000000000000000000000000000000000000..fa052c473b0158138c6b00c1b44a28127104e7b5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02294.java @@ -0,0 +1,145 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02294") +public class BenchmarkTest02294 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02294")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02295.java b/OWASP DATASET/BenchmarkTest02295.java new file mode 100644 index 0000000000000000000000000000000000000000..142d9c58560854f4635b21dcf8ad43710282e4eb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02295.java @@ -0,0 +1,145 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02295") +public class BenchmarkTest02295 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02295")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02296.java b/OWASP DATASET/BenchmarkTest02296.java new file mode 100644 index 0000000000000000000000000000000000000000..8efd4c98f20e6e7de9b216d9fe96dea88c7f4bc4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02296.java @@ -0,0 +1,141 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02296") +public class BenchmarkTest02296 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02296")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + // java.security.SecureRandom random = new java.security.SecureRandom(); + // byte[] iv = random.generateSeed(16); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg2", "AES/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02297.java b/OWASP DATASET/BenchmarkTest02297.java new file mode 100644 index 0000000000000000000000000000000000000000..cd84ea0af0fff0647ceede65f93083065c67eda5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02297.java @@ -0,0 +1,146 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02297") +public class BenchmarkTest02297 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02297")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + // java.security.SecureRandom random = new java.security.SecureRandom(); + // byte[] iv = random.generateSeed(16); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg2", "AES/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02298.java b/OWASP DATASET/BenchmarkTest02298.java new file mode 100644 index 0000000000000000000000000000000000000000..50be70b0a1d3e2b9b7030e848e48b0e6774f4223 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02298.java @@ -0,0 +1,143 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02298") +public class BenchmarkTest02298 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02298")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + // java.security.SecureRandom random = new java.security.SecureRandom(); + // byte[] iv = random.generateSeed(16); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg2", "AES/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02299.java b/OWASP DATASET/BenchmarkTest02299.java new file mode 100644 index 0000000000000000000000000000000000000000..2522d0ae52f77bf762a0c3914f02a4287b789a26 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02299.java @@ -0,0 +1,126 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest02299") +public class BenchmarkTest02299 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02299")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + javax.naming.directory.DirContext ctx = ads.getDirContext(); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person)(uid=" + bar + "))"; + // System.out.println("Filter " + filter); + boolean found = false; + javax.naming.NamingEnumeration results = + ctx.search(base, filter, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02300.java b/OWASP DATASET/BenchmarkTest02300.java new file mode 100644 index 0000000000000000000000000000000000000000..1d883440754871410f4c001934026379ab512319 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02300.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02300") +public class BenchmarkTest02300 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02300")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a20919 = param; // assign + StringBuilder b20919 = new StringBuilder(a20919); // stick in stringbuilder + b20919.append(" SafeStuff"); // append some safe content + b20919.replace( + b20919.length() - "Chars".length(), + b20919.length(), + "Chars"); // replace some of the end content + java.util.HashMap map20919 = new java.util.HashMap(); + map20919.put("key20919", b20919.toString()); // put in a collection + String c20919 = (String) map20919.get("key20919"); // get it back out + String d20919 = c20919.substring(0, c20919.length() - 1); // extract most of it + String e20919 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d20919.getBytes()))); // B64 encode and decode it + String f20919 = e20919.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g20919 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g20919); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02301.java b/OWASP DATASET/BenchmarkTest02301.java new file mode 100644 index 0000000000000000000000000000000000000000..afb8cf481e799b56dcff97fcc15f759baac682b4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02301.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02301") +public class BenchmarkTest02301 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02301")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + java.io.File fileTarget = new java.io.File(bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02302.java b/OWASP DATASET/BenchmarkTest02302.java new file mode 100644 index 0000000000000000000000000000000000000000..2cfed217e0b092fcc80e269c67c4320e5c11cff8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02302.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02302") +public class BenchmarkTest02302 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02302")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + java.io.File fileTarget = new java.io.File(bar, "/Test.txt"); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02303.java b/OWASP DATASET/BenchmarkTest02303.java new file mode 100644 index 0000000000000000000000000000000000000000..0fcb18184f755157de9443a95423d2e24d2232ca --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02303.java @@ -0,0 +1,128 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02303") +public class BenchmarkTest02303 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02303")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(new java.io.File(fileName)); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting FileInputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02304.java b/OWASP DATASET/BenchmarkTest02304.java new file mode 100644 index 0000000000000000000000000000000000000000..d9f6242502e5a31612ca0f420d965d369448e0ec --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02304.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02304") +public class BenchmarkTest02304 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02304")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(fileName); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02305.java b/OWASP DATASET/BenchmarkTest02305.java new file mode 100644 index 0000000000000000000000000000000000000000..7601ee638cca1ce809040c1e8aa17e202ec2b104 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02305.java @@ -0,0 +1,132 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest02305") +public class BenchmarkTest02305 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02305")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + bar + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + + javax.naming.directory.DirContext ctx = ads.getDirContext(); + javax.naming.directory.InitialDirContext idc = + (javax.naming.directory.InitialDirContext) ctx; + boolean found = false; + javax.naming.NamingEnumeration results = + idc.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02306.java b/OWASP DATASET/BenchmarkTest02306.java new file mode 100644 index 0000000000000000000000000000000000000000..1d825bed3de95bbe548fc377030152639a63b51b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02306.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest02306") +public class BenchmarkTest02306 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02306")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person)(uid=" + bar + "))"; + + javax.naming.directory.DirContext ctx = ads.getDirContext(); + javax.naming.directory.InitialDirContext idc = + (javax.naming.directory.InitialDirContext) ctx; + boolean found = false; + javax.naming.NamingEnumeration results = + idc.search(base, filter, sc); + + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02307.java b/OWASP DATASET/BenchmarkTest02307.java new file mode 100644 index 0000000000000000000000000000000000000000..5c129c93e7d930f8ed9ac9fa098c8d9b7d9c1973 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02307.java @@ -0,0 +1,151 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02307") +public class BenchmarkTest02307 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02307")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("SHA1", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02308.java b/OWASP DATASET/BenchmarkTest02308.java new file mode 100644 index 0000000000000000000000000000000000000000..1f3b3119f7cc230e17fdb1e401450a0c1505e5e2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02308.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02308") +public class BenchmarkTest02308 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02308")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02309.java b/OWASP DATASET/BenchmarkTest02309.java new file mode 100644 index 0000000000000000000000000000000000000000..6256fbbc4e5f76567d4fadd93de1c1622ae257cf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02309.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02309") +public class BenchmarkTest02309 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02309")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = + java.security.MessageDigest.getInstance("SHA-512", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02310.java b/OWASP DATASET/BenchmarkTest02310.java new file mode 100644 index 0000000000000000000000000000000000000000..8c6962fb5a742d75f2c94a1c4ebb55ebe9d1de57 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02310.java @@ -0,0 +1,126 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02310") +public class BenchmarkTest02310 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02310")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = + java.security.MessageDigest.getInstance("SHA-512", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02311.java b/OWASP DATASET/BenchmarkTest02311.java new file mode 100644 index 0000000000000000000000000000000000000000..07fb539af13a8835d905f6bad74e5c69c965f4ae --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02311.java @@ -0,0 +1,122 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02311") +public class BenchmarkTest02311 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02311")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02312.java b/OWASP DATASET/BenchmarkTest02312.java new file mode 100644 index 0000000000000000000000000000000000000000..ffaa394678631971da4143fb1649f94245434647 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02312.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02312") +public class BenchmarkTest02312 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02312")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-256"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02313.java b/OWASP DATASET/BenchmarkTest02313.java new file mode 100644 index 0000000000000000000000000000000000000000..a3d2ff8f6767f422b1df705649001ccbcaea10a0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02313.java @@ -0,0 +1,98 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02313") +public class BenchmarkTest02313 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02313")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + java.io.PrintWriter out = response.getWriter(); + out.write("\n\n\n

"); + out.format(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + out.write("\n

\n\n"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a31085 = param; // assign + StringBuilder b31085 = new StringBuilder(a31085); // stick in stringbuilder + b31085.append(" SafeStuff"); // append some safe content + b31085.replace( + b31085.length() - "Chars".length(), + b31085.length(), + "Chars"); // replace some of the end content + java.util.HashMap map31085 = new java.util.HashMap(); + map31085.put("key31085", b31085.toString()); // put in a collection + String c31085 = (String) map31085.get("key31085"); // get it back out + String d31085 = c31085.substring(0, c31085.length() - 1); // extract most of it + String e31085 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d31085.getBytes()))); // B64 encode and decode it + String f31085 = e31085.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g31085 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g31085); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02314.java b/OWASP DATASET/BenchmarkTest02314.java new file mode 100644 index 0000000000000000000000000000000000000000..a316c45b166eea2cf3637611fa8e9ca2441b2ad3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02314.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02314") +public class BenchmarkTest02314 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02314")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(java.util.Locale.US, bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02315.java b/OWASP DATASET/BenchmarkTest02315.java new file mode 100644 index 0000000000000000000000000000000000000000..fbae22cd9a81ffd498005558904cc448cb6f2833 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02315.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02315") +public class BenchmarkTest02315 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02315")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().format("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02316.java b/OWASP DATASET/BenchmarkTest02316.java new file mode 100644 index 0000000000000000000000000000000000000000..b6cdf9f2c21b3ad0ec1615635dc3b2fc00c95470 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02316.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02316") +public class BenchmarkTest02316 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02316")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02317.java b/OWASP DATASET/BenchmarkTest02317.java new file mode 100644 index 0000000000000000000000000000000000000000..3d576ae779fac18304bc7d862cdf2bd1b964e5ff --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02317.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02317") +public class BenchmarkTest02317 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02317")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02318.java b/OWASP DATASET/BenchmarkTest02318.java new file mode 100644 index 0000000000000000000000000000000000000000..2cebfb4ca17b35c3ec8ed8d48f492ac1cb625c7b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02318.java @@ -0,0 +1,73 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02318") +public class BenchmarkTest02318 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02318")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar.toCharArray()); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02319.java b/OWASP DATASET/BenchmarkTest02319.java new file mode 100644 index 0000000000000000000000000000000000000000..2a77061f7120ad3871d17d85fcafc986e19722c0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02319.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02319") +public class BenchmarkTest02319 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02319")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02320.java b/OWASP DATASET/BenchmarkTest02320.java new file mode 100644 index 0000000000000000000000000000000000000000..9c37f389d8fd1a93f21c49b506b08e0f575910da --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02320.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02320") +public class BenchmarkTest02320 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02320")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02321.java b/OWASP DATASET/BenchmarkTest02321.java new file mode 100644 index 0000000000000000000000000000000000000000..4f527b58bb79e7057efa096aac2c143579b17e54 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02321.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02321") +public class BenchmarkTest02321 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02321")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {bar, "b"}; + response.getWriter().printf("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a32510 = param; // assign + StringBuilder b32510 = new StringBuilder(a32510); // stick in stringbuilder + b32510.append(" SafeStuff"); // append some safe content + b32510.replace( + b32510.length() - "Chars".length(), + b32510.length(), + "Chars"); // replace some of the end content + java.util.HashMap map32510 = new java.util.HashMap(); + map32510.put("key32510", b32510.toString()); // put in a collection + String c32510 = (String) map32510.get("key32510"); // get it back out + String d32510 = c32510.substring(0, c32510.length() - 1); // extract most of it + String e32510 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d32510.getBytes()))); // B64 encode and decode it + String f32510 = e32510.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f32510); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02322.java b/OWASP DATASET/BenchmarkTest02322.java new file mode 100644 index 0000000000000000000000000000000000000000..dcf3ffcd50de224ce963119cb44d6c4af7d5a19c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02322.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02322") +public class BenchmarkTest02322 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02322")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {bar, "b"}; + response.getWriter().printf("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02323.java b/OWASP DATASET/BenchmarkTest02323.java new file mode 100644 index 0000000000000000000000000000000000000000..31d098e21f3e8945a1f746757e855ee81d80a1ff --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02323.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02323") +public class BenchmarkTest02323 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02323")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {bar, "b"}; + response.getWriter().printf("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02324.java b/OWASP DATASET/BenchmarkTest02324.java new file mode 100644 index 0000000000000000000000000000000000000000..86615b1cfe28c0fee97bf57e0425b8dc32dcae6a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02324.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02324") +public class BenchmarkTest02324 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02324")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {bar, "b"}; + response.getWriter().printf("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz12198 = new StringBuilder(param); + bar = sbxyz12198.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02325.java b/OWASP DATASET/BenchmarkTest02325.java new file mode 100644 index 0000000000000000000000000000000000000000..6585944f60a04562ed3c11f1c93229ec85de78fc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02325.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02325") +public class BenchmarkTest02325 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02325")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02326.java b/OWASP DATASET/BenchmarkTest02326.java new file mode 100644 index 0000000000000000000000000000000000000000..12f0c989101eaee3eae02ac1001a24f53b7a0179 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02326.java @@ -0,0 +1,80 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02326") +public class BenchmarkTest02326 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02326")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar.toCharArray()); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02327.java b/OWASP DATASET/BenchmarkTest02327.java new file mode 100644 index 0000000000000000000000000000000000000000..3e362aa96056db3b4601ff4fcff5b97a29442548 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02327.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02327") +public class BenchmarkTest02327 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02327")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar.toCharArray(), 0, length); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02328.java b/OWASP DATASET/BenchmarkTest02328.java new file mode 100644 index 0000000000000000000000000000000000000000..e20b9eaeb02bf0631c4ff4c2e4438b274012e74a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02328.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02328") +public class BenchmarkTest02328 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02328")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar.toCharArray(), 0, length); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02329.java b/OWASP DATASET/BenchmarkTest02329.java new file mode 100644 index 0000000000000000000000000000000000000000..ffb545dd9c30d65930d1d085301b1b83031b1515 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02329.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02329") +public class BenchmarkTest02329 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02329")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar.toCharArray(), 0, length); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02330.java b/OWASP DATASET/BenchmarkTest02330.java new file mode 100644 index 0000000000000000000000000000000000000000..1259b3c435695c72fba9485f8cf0528ac7434ef6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02330.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02330") +public class BenchmarkTest02330 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02330")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar.toCharArray(), 0, length); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02331.java b/OWASP DATASET/BenchmarkTest02331.java new file mode 100644 index 0000000000000000000000000000000000000000..c04d29e3aefa4edf076ba14b10ceafa00fc9331c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02331.java @@ -0,0 +1,73 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02331") +public class BenchmarkTest02331 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02331")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02332.java b/OWASP DATASET/BenchmarkTest02332.java new file mode 100644 index 0000000000000000000000000000000000000000..08648f3ec1ab819402ab0df261b6b39036378f0c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02332.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02332") +public class BenchmarkTest02332 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02332")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02333.java b/OWASP DATASET/BenchmarkTest02333.java new file mode 100644 index 0000000000000000000000000000000000000000..166124a7d35db8c51544d1c668a3de7cdb2cf73d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02333.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02333") +public class BenchmarkTest02333 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02333")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(); + + pb.command(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02334.java b/OWASP DATASET/BenchmarkTest02334.java new file mode 100644 index 0000000000000000000000000000000000000000..b10cfd64408c7938291edfe5cc3a0d6b53775e18 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02334.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02334") +public class BenchmarkTest02334 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02334")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(); + + pb.command(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02335.java b/OWASP DATASET/BenchmarkTest02335.java new file mode 100644 index 0000000000000000000000000000000000000000..688df877eb9f9c52d4cdbd2d8a486ca72abc24b7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02335.java @@ -0,0 +1,105 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02335") +public class BenchmarkTest02335 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02335")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + String a1 = ""; + String a2 = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + } else { + a1 = "sh"; + a2 = "-c"; + } + String[] args = {a1, a2, "echo " + bar}; + + ProcessBuilder pb = new ProcessBuilder(); + + pb.command(args); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02336.java b/OWASP DATASET/BenchmarkTest02336.java new file mode 100644 index 0000000000000000000000000000000000000000..2af709a152306b484bc22727194ac69b35a1951f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02336.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02336") +public class BenchmarkTest02336 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02336")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + String a1 = ""; + String a2 = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + } else { + a1 = "sh"; + a2 = "-c"; + } + String[] args = {a1, a2, "echo " + bar}; + + ProcessBuilder pb = new ProcessBuilder(); + + pb.command(args); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a61280 = param; // assign + StringBuilder b61280 = new StringBuilder(a61280); // stick in stringbuilder + b61280.append(" SafeStuff"); // append some safe content + b61280.replace( + b61280.length() - "Chars".length(), + b61280.length(), + "Chars"); // replace some of the end content + java.util.HashMap map61280 = new java.util.HashMap(); + map61280.put("key61280", b61280.toString()); // put in a collection + String c61280 = (String) map61280.get("key61280"); // get it back out + String d61280 = c61280.substring(0, c61280.length() - 1); // extract most of it + String e61280 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d61280.getBytes()))); // B64 encode and decode it + String f61280 = e61280.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g61280 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g61280); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02337.java b/OWASP DATASET/BenchmarkTest02337.java new file mode 100644 index 0000000000000000000000000000000000000000..ea499a3bb6530dd4e6ef03b0b48b5d6bb1df415b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02337.java @@ -0,0 +1,125 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02337") +public class BenchmarkTest02337 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02337")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map19180 = new java.util.HashMap(); + map19180.put("keyA-19180", "a_Value"); // put some stuff in the collection + map19180.put("keyB-19180", param); // put it in a collection + map19180.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map19180.get("keyB-19180"); // get it back out + bar = (String) map19180.get("keyA-19180"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02338.java b/OWASP DATASET/BenchmarkTest02338.java new file mode 100644 index 0000000000000000000000000000000000000000..281b2801980487b0613989091505ef7fb2647000 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02338.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02338") +public class BenchmarkTest02338 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02338")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02339.java b/OWASP DATASET/BenchmarkTest02339.java new file mode 100644 index 0000000000000000000000000000000000000000..e646a315db1c1fb78e973d3aeceee99f1bf0c1ba --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02339.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest02339") +public class BenchmarkTest02339 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02339")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02340.java b/OWASP DATASET/BenchmarkTest02340.java new file mode 100644 index 0000000000000000000000000000000000000000..13d2fa7b84087978f5d98eb6b5a8056271b85b9d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02340.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02340") +public class BenchmarkTest02340 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02340")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02341.java b/OWASP DATASET/BenchmarkTest02341.java new file mode 100644 index 0000000000000000000000000000000000000000..49b536124c1376da6589861d2c07dc014d9c255f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02341.java @@ -0,0 +1,107 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02341") +public class BenchmarkTest02341 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02341")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02342.java b/OWASP DATASET/BenchmarkTest02342.java new file mode 100644 index 0000000000000000000000000000000000000000..98298d0e8345d5418f7ce7994081c340c367960c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02342.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02342") +public class BenchmarkTest02342 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02342")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02343.java b/OWASP DATASET/BenchmarkTest02343.java new file mode 100644 index 0000000000000000000000000000000000000000..2e59856914469f1951999fd76df84188a9ffd5ab --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02343.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02343") +public class BenchmarkTest02343 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02343")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + String[] argsEnv = {"Foo=bar"}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = + r.exec(cmd + bar, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02344.java b/OWASP DATASET/BenchmarkTest02344.java new file mode 100644 index 0000000000000000000000000000000000000000..c100520735852e0bfe7719d824b7ca730391e642 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02344.java @@ -0,0 +1,90 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02344") +public class BenchmarkTest02344 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02344")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + try { + Process p = r.exec(cmd, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02345.java b/OWASP DATASET/BenchmarkTest02345.java new file mode 100644 index 0000000000000000000000000000000000000000..165edef205140b95bf937c751088e9e568150960 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02345.java @@ -0,0 +1,141 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02345") +public class BenchmarkTest02345 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02345")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + getNextNumber(numGen, randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeBystander"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + void getNextNumber(java.util.Random generator, byte[] barray) { + generator.nextBytes(barray); + } + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map60514 = new java.util.HashMap(); + map60514.put("keyA-60514", "a-Value"); // put some stuff in the collection + map60514.put("keyB-60514", param); // put it in a collection + map60514.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map60514.get("keyB-60514"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02346.java b/OWASP DATASET/BenchmarkTest02346.java new file mode 100644 index 0000000000000000000000000000000000000000..17fcbac920e16b782b53a58a69e74a5ecdfda941 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02346.java @@ -0,0 +1,140 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02346") +public class BenchmarkTest02346 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02346")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + getNextNumber(numGen, randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeBystander"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + void getNextNumber(java.util.Random generator, byte[] barray) { + generator.nextBytes(barray); + } + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz9692 = new StringBuilder(param); + bar = sbxyz9692.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02347.java b/OWASP DATASET/BenchmarkTest02347.java new file mode 100644 index 0000000000000000000000000000000000000000..5186e11fb8b527a0c54da3084b24bedee555c4c4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02347.java @@ -0,0 +1,146 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02347") +public class BenchmarkTest02347 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02347")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02348.java b/OWASP DATASET/BenchmarkTest02348.java new file mode 100644 index 0000000000000000000000000000000000000000..7d19540d2546aff83772f477b9a559412ee51c12 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02348.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02348") +public class BenchmarkTest02348 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02348")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + try { + int randNumber = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "SafeInga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt(int) - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt(int) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map48532 = new java.util.HashMap(); + map48532.put("keyA-48532", "a-Value"); // put some stuff in the collection + map48532.put("keyB-48532", param); // put it in a collection + map48532.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map48532.get("keyB-48532"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02349.java b/OWASP DATASET/BenchmarkTest02349.java new file mode 100644 index 0000000000000000000000000000000000000000..d7008564b1817ac8d0c3c94ccafda85369424c5a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02349.java @@ -0,0 +1,144 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02349") +public class BenchmarkTest02349 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02349")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + try { + int randNumber = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "SafeInga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt(int) - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt(int) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a55770 = param; // assign + StringBuilder b55770 = new StringBuilder(a55770); // stick in stringbuilder + b55770.append(" SafeStuff"); // append some safe content + b55770.replace( + b55770.length() - "Chars".length(), + b55770.length(), + "Chars"); // replace some of the end content + java.util.HashMap map55770 = new java.util.HashMap(); + map55770.put("key55770", b55770.toString()); // put in a collection + String c55770 = (String) map55770.get("key55770"); // get it back out + String d55770 = c55770.substring(0, c55770.length() - 1); // extract most of it + String e55770 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d55770.getBytes()))); // B64 encode and decode it + String f55770 = e55770.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f55770); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02350.java b/OWASP DATASET/BenchmarkTest02350.java new file mode 100644 index 0000000000000000000000000000000000000000..d7e86659825bfe4206f9a3daa7321bbad3ab0c74 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02350.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02350") +public class BenchmarkTest02350 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02350")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + try { + int randNumber = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "SafeInga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt(int) - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt(int) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02351.java b/OWASP DATASET/BenchmarkTest02351.java new file mode 100644 index 0000000000000000000000000000000000000000..d151c548ea81ad0ae0fec1d60f9390d2e40aecaa --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02351.java @@ -0,0 +1,144 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02351") +public class BenchmarkTest02351 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02351")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + try { + long l = java.security.SecureRandom.getInstance("SHA1PRNG").nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "SafeLogan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextLong() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextLong() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a14991 = param; // assign + StringBuilder b14991 = new StringBuilder(a14991); // stick in stringbuilder + b14991.append(" SafeStuff"); // append some safe content + b14991.replace( + b14991.length() - "Chars".length(), + b14991.length(), + "Chars"); // replace some of the end content + java.util.HashMap map14991 = new java.util.HashMap(); + map14991.put("key14991", b14991.toString()); // put in a collection + String c14991 = (String) map14991.get("key14991"); // get it back out + String d14991 = c14991.substring(0, c14991.length() - 1); // extract most of it + String e14991 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d14991.getBytes()))); // B64 encode and decode it + String f14991 = e14991.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f14991); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02352.java b/OWASP DATASET/BenchmarkTest02352.java new file mode 100644 index 0000000000000000000000000000000000000000..f6d1dbfb61ab9b0c9d0d2550ade2490c7e144d79 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02352.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest02352") +public class BenchmarkTest02352 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02352")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String^,java.lang.Object) + request.getSession().setAttribute(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: '10340' saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02353.java b/OWASP DATASET/BenchmarkTest02353.java new file mode 100644 index 0000000000000000000000000000000000000000..2e8bb2bfd1fb3c79477e192ae49025cd21226705 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02353.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02353") +public class BenchmarkTest02353 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02353")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02354.java b/OWASP DATASET/BenchmarkTest02354.java new file mode 100644 index 0000000000000000000000000000000000000000..37184ef31a1e87cf836341e323269784f9c3467e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02354.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02354") +public class BenchmarkTest02354 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02354")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, new int[] {1, 2}); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02355.java b/OWASP DATASET/BenchmarkTest02355.java new file mode 100644 index 0000000000000000000000000000000000000000..18b0317f6137114219e668340f5ddf0935283f12 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02355.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02355") +public class BenchmarkTest02355 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02355")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, new String[] {"Column1", "Column2"}); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02356.java b/OWASP DATASET/BenchmarkTest02356.java new file mode 100644 index 0000000000000000000000000000000000000000..3d8897e46ac16e298da3eb3bd30e6042ec386136 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02356.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02356") +public class BenchmarkTest02356 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02356")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.execute(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring execute method doesn't return results."); + + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02357.java b/OWASP DATASET/BenchmarkTest02357.java new file mode 100644 index 0000000000000000000000000000000000000000..e825dc3671c587d1d1f41fa10304a2e28bbcdb3d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02357.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02357") +public class BenchmarkTest02357 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02357")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.query( + sql, + new org.springframework.jdbc.core.RowMapper() { + @Override + public String mapRow(java.sql.ResultSet rs, int rowNum) + throws java.sql.SQLException { + try { + return rs.getString("USERNAME"); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper + .hideSQLErrors) { + return "Error processing query."; + } else throw e; + } + } + }); + response.getWriter().println("Your results are: "); + + for (String s : results) { + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(s) + "
"); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02358.java b/OWASP DATASET/BenchmarkTest02358.java new file mode 100644 index 0000000000000000000000000000000000000000..fbd6824e6a567d5bb2dcb1885a82950fb4783331 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02358.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02358") +public class BenchmarkTest02358 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02358")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List> list = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForList(sql); + response.getWriter().println("Your results are:
"); + + // System.out.println("Your results are"); + + for (Object o : list) { + response.getWriter() + .println( + org.owasp.esapi.ESAPI.encoder().encodeForHTML(o.toString()) + + "
"); + // System.out.println(o.toString()); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02359.java b/OWASP DATASET/BenchmarkTest02359.java new file mode 100644 index 0000000000000000000000000000000000000000..627118f90449456b0ea521f5a79f785530479480 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02359.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02359") +public class BenchmarkTest02359 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02359")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // Long results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForLong(sql); + Long results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Long.class); + response.getWriter().println("Your results are: " + String.valueOf(results)); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02360.java b/OWASP DATASET/BenchmarkTest02360.java new file mode 100644 index 0000000000000000000000000000000000000000..7ee083d7e52cb33b023a9e7f32d303687d0d456c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02360.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02360") +public class BenchmarkTest02360 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02360")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // Long results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForLong(sql); + Long results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Long.class); + response.getWriter().println("Your results are: " + String.valueOf(results)); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02361.java b/OWASP DATASET/BenchmarkTest02361.java new file mode 100644 index 0000000000000000000000000000000000000000..9b859c76428100c028664d1e1bfaf7a51780c5b8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02361.java @@ -0,0 +1,98 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02361") +public class BenchmarkTest02361 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02361")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + String sql = + "SELECT TOP 1 USERNAME from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + Object results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, new Object[] {}, String.class); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(results.toString())); + // System.out.println(results.toString()); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02362.java b/OWASP DATASET/BenchmarkTest02362.java new file mode 100644 index 0000000000000000000000000000000000000000..e577df2c58b9def58fd774e9b3fc73b4589cc96c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02362.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02362") +public class BenchmarkTest02362 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02362")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + org.springframework.jdbc.support.rowset.SqlRowSet results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForRowSet(sql); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + while (results.next()) { + response.getWriter() + .println( + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(results.getString("USERNAME")) + + " "); + // System.out.println(results.getString("USERNAME")); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02363.java b/OWASP DATASET/BenchmarkTest02363.java new file mode 100644 index 0000000000000000000000000000000000000000..f377f235544e6ef12b0fc62601b8d58827b16d4e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02363.java @@ -0,0 +1,107 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02363") +public class BenchmarkTest02363 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02363")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a21456 = param; // assign + StringBuilder b21456 = new StringBuilder(a21456); // stick in stringbuilder + b21456.append(" SafeStuff"); // append some safe content + b21456.replace( + b21456.length() - "Chars".length(), + b21456.length(), + "Chars"); // replace some of the end content + java.util.HashMap map21456 = new java.util.HashMap(); + map21456.put("key21456", b21456.toString()); // put in a collection + String c21456 = (String) map21456.get("key21456"); // get it back out + String d21456 = c21456.substring(0, c21456.length() - 1); // extract most of it + String e21456 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d21456.getBytes()))); // B64 encode and decode it + String f21456 = e21456.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g21456 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g21456); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02364.java b/OWASP DATASET/BenchmarkTest02364.java new file mode 100644 index 0000000000000000000000000000000000000000..7d20f7c835598403b527c3d5738a2f7205e693d3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02364.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02364") +public class BenchmarkTest02364 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02364")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02365.java b/OWASP DATASET/BenchmarkTest02365.java new file mode 100644 index 0000000000000000000000000000000000000000..904701a2e6f40e75474934003b2691134315544c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02365.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02365") +public class BenchmarkTest02365 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02365")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02366.java b/OWASP DATASET/BenchmarkTest02366.java new file mode 100644 index 0000000000000000000000000000000000000000..5e1715ab4dba8519ad6047b6d9d6e14277c0e4cf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02366.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02366") +public class BenchmarkTest02366 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02366")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02367.java b/OWASP DATASET/BenchmarkTest02367.java new file mode 100644 index 0000000000000000000000000000000000000000..3cf526b435d159334bf51e8bbed425ad0fb82fd9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02367.java @@ -0,0 +1,105 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02367") +public class BenchmarkTest02367 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02367")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a41891 = param; // assign + StringBuilder b41891 = new StringBuilder(a41891); // stick in stringbuilder + b41891.append(" SafeStuff"); // append some safe content + b41891.replace( + b41891.length() - "Chars".length(), + b41891.length(), + "Chars"); // replace some of the end content + java.util.HashMap map41891 = new java.util.HashMap(); + map41891.put("key41891", b41891.toString()); // put in a collection + String c41891 = (String) map41891.get("key41891"); // get it back out + String d41891 = c41891.substring(0, c41891.length() - 1); // extract most of it + String e41891 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d41891.getBytes()))); // B64 encode and decode it + String f41891 = e41891.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g41891 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g41891); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02368.java b/OWASP DATASET/BenchmarkTest02368.java new file mode 100644 index 0000000000000000000000000000000000000000..2a33327b133d14cb0bf338189b59f4c73b5fb220 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02368.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02368") +public class BenchmarkTest02368 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02368")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02369.java b/OWASP DATASET/BenchmarkTest02369.java new file mode 100644 index 0000000000000000000000000000000000000000..982b944920b7f320256db8699a4a9b8322c90042 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02369.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02369") +public class BenchmarkTest02369 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02369")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02370.java b/OWASP DATASET/BenchmarkTest02370.java new file mode 100644 index 0000000000000000000000000000000000000000..7dea340aacd227f3e658ce33f3c26e9545f4417a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02370.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest02370") +public class BenchmarkTest02370 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String param = ""; + boolean flag = true; + java.util.Enumeration names = request.getParameterNames(); + while (names.hasMoreElements() && flag) { + String name = (String) names.nextElement(); + String[] values = request.getParameterValues(name); + if (values != null) { + for (int i = 0; i < values.length && flag; i++) { + String value = values[i]; + if (value.equals("BenchmarkTest02370")) { + param = name; + flag = false; + } + } + } + } + + String bar = doSomething(request, param); + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + org.w3c.dom.NodeList nodeList = + (org.w3c.dom.NodeList) + xp.compile(expression) + .evaluate(xmlDocument, javax.xml.xpath.XPathConstants.NODESET); + + response.getWriter().println("Your query results are:
"); + + for (int i = 0; i < nodeList.getLength(); i++) { + org.w3c.dom.Element value = (org.w3c.dom.Element) nodeList.item(i); + response.getWriter().println(value.getTextContent() + "
"); + } + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02371.java b/OWASP DATASET/BenchmarkTest02371.java new file mode 100644 index 0000000000000000000000000000000000000000..d5e74f610e4a6012d6bee59d373a7deebb680134 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02371.java @@ -0,0 +1,159 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02371") +public class BenchmarkTest02371 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02371"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02372.java b/OWASP DATASET/BenchmarkTest02372.java new file mode 100644 index 0000000000000000000000000000000000000000..611abe66ef3c3f3bb0253778950b273c57c27ae5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02372.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02372") +public class BenchmarkTest02372 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02372"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = org.owasp.benchmark.helpers.Utils.getCipher(); + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02373.java b/OWASP DATASET/BenchmarkTest02373.java new file mode 100644 index 0000000000000000000000000000000000000000..b293f741ab771843bde6fd3affee00a7074a4b10 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02373.java @@ -0,0 +1,133 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02373") +public class BenchmarkTest02373 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02373"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02374.java b/OWASP DATASET/BenchmarkTest02374.java new file mode 100644 index 0000000000000000000000000000000000000000..172b078ed86818a3e9c18ed6772e30d70fc0a507 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02374.java @@ -0,0 +1,138 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02374") +public class BenchmarkTest02374 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02374"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02375.java b/OWASP DATASET/BenchmarkTest02375.java new file mode 100644 index 0000000000000000000000000000000000000000..ccf521d36fbb6e0f004e217bb5f947d455410ba1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02375.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02375") +public class BenchmarkTest02375 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02375"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02376.java b/OWASP DATASET/BenchmarkTest02376.java new file mode 100644 index 0000000000000000000000000000000000000000..c8ae44ef014bc36d978dcc8ec7b8193e9efb8159 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02376.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest02376") +public class BenchmarkTest02376 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02376"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + javax.naming.directory.DirContext ctx = ads.getDirContext(); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + bar + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + // System.out.println("Filter " + filter); + boolean found = false; + javax.naming.NamingEnumeration results = + ctx.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02377.java b/OWASP DATASET/BenchmarkTest02377.java new file mode 100644 index 0000000000000000000000000000000000000000..af07ebd06da6e180c6b828dca73fe931bc7c2564 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02377.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02377") +public class BenchmarkTest02377 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02377"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + java.io.File fileTarget = new java.io.File(bar, "/Test.txt"); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02378.java b/OWASP DATASET/BenchmarkTest02378.java new file mode 100644 index 0000000000000000000000000000000000000000..2e5edc4a2e2657c245dd6f34686baa7eb6d017e7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02378.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02378") +public class BenchmarkTest02378 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02378"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + // FILE URIs are tricky because they are different between Mac and Windows because of lack + // of standardization. + // Mac requires an extra slash for some reason. + String startURIslashes = ""; + if (System.getProperty("os.name").indexOf("Windows") != -1) + if (System.getProperty("os.name").indexOf("Windows") != -1) startURIslashes = "/"; + else startURIslashes = "//"; + + try { + java.net.URI fileURI = + new java.net.URI( + "file:" + + startURIslashes + + org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + .replace('\\', '/') + .replace(' ', '_') + + bar); + java.io.File fileTarget = new java.io.File(fileURI); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } catch (java.net.URISyntaxException e) { + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02379.java b/OWASP DATASET/BenchmarkTest02379.java new file mode 100644 index 0000000000000000000000000000000000000000..d5452023cc9eb42c2a0f0fd9b70f1f866f868dc0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02379.java @@ -0,0 +1,107 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02379") +public class BenchmarkTest02379 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02379"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + // FILE URIs are tricky because they are different between Mac and Windows because of lack + // of standardization. + // Mac requires an extra slash for some reason. + String startURIslashes = ""; + if (System.getProperty("os.name").indexOf("Windows") != -1) + if (System.getProperty("os.name").indexOf("Windows") != -1) startURIslashes = "/"; + else startURIslashes = "//"; + + try { + java.net.URI fileURI = + new java.net.URI( + "file", + null, + startURIslashes + + org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + .replace('\\', java.io.File.separatorChar) + .replace(' ', '_') + + bar, + null, + null); + java.io.File fileTarget = new java.io.File(fileURI); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } catch (java.net.URISyntaxException e) { + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02380.java b/OWASP DATASET/BenchmarkTest02380.java new file mode 100644 index 0000000000000000000000000000000000000000..c4662b525f85cb6d3f866893088dc15f5d6851db --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02380.java @@ -0,0 +1,105 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02380") +public class BenchmarkTest02380 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02380"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName)); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a76789 = param; // assign + StringBuilder b76789 = new StringBuilder(a76789); // stick in stringbuilder + b76789.append(" SafeStuff"); // append some safe content + b76789.replace( + b76789.length() - "Chars".length(), + b76789.length(), + "Chars"); // replace some of the end content + java.util.HashMap map76789 = new java.util.HashMap(); + map76789.put("key76789", b76789.toString()); // put in a collection + String c76789 = (String) map76789.get("key76789"); // get it back out + String d76789 = c76789.substring(0, c76789.length() - 1); // extract most of it + String e76789 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d76789.getBytes()))); // B64 encode and decode it + String f76789 = e76789.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g76789 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g76789); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02381.java b/OWASP DATASET/BenchmarkTest02381.java new file mode 100644 index 0000000000000000000000000000000000000000..3f57c2a55e9399834272fbeea757e881a308a859 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02381.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02381") +public class BenchmarkTest02381 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02381"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + try ( + // Create the file first so the test won't throw an exception if it doesn't exist. + // Note: Don't actually do this because this method signature could cause a tool to find + // THIS file constructor + // as a vuln, rather than the File signature we are trying to actually test. + // If necessary, just run the benchmark twice. The 1st run should create all the necessary + // files. + // new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar).createNewFile(); + + java.io.FileOutputStream fos = + new java.io.FileOutputStream(new java.io.FileInputStream(fileName).getFD()); ) { + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map75774 = new java.util.HashMap(); + map75774.put("keyA-75774", "a_Value"); // put some stuff in the collection + map75774.put("keyB-75774", param); // put it in a collection + map75774.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map75774.get("keyB-75774"); // get it back out + bar = (String) map75774.get("keyA-75774"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02382.java b/OWASP DATASET/BenchmarkTest02382.java new file mode 100644 index 0000000000000000000000000000000000000000..947a0e631a6650ef44b5c76ad65824d7b2d2f07b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02382.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02382") +public class BenchmarkTest02382 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02382"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName, false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02383.java b/OWASP DATASET/BenchmarkTest02383.java new file mode 100644 index 0000000000000000000000000000000000000000..0a13dee9282e25712ac6d33316ecec0442b409e0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02383.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02383") +public class BenchmarkTest02383 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02383"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map53518 = new java.util.HashMap(); + map53518.put("keyA-53518", "a-Value"); // put some stuff in the collection + map53518.put("keyB-53518", param); // put it in a collection + map53518.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map53518.get("keyB-53518"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02384.java b/OWASP DATASET/BenchmarkTest02384.java new file mode 100644 index 0000000000000000000000000000000000000000..d6740554c56aafc24fa53945af74b2e69a4199e4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02384.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest02384") +public class BenchmarkTest02384 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02384"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person)(uid=" + bar + "))"; + + javax.naming.directory.DirContext ctx = ads.getDirContext(); + javax.naming.directory.InitialDirContext idc = + (javax.naming.directory.InitialDirContext) ctx; + boolean found = false; + javax.naming.NamingEnumeration results = + idc.search(base, filter, sc); + + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02385.java b/OWASP DATASET/BenchmarkTest02385.java new file mode 100644 index 0000000000000000000000000000000000000000..5ab784779dc3790bd2da167669d723caa3eb6b69 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02385.java @@ -0,0 +1,125 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02385") +public class BenchmarkTest02385 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02385"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("SHA1", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02386.java b/OWASP DATASET/BenchmarkTest02386.java new file mode 100644 index 0000000000000000000000000000000000000000..c315f87797b60d8cb808e64e697f664119b3e816 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02386.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02386") +public class BenchmarkTest02386 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02386"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02387.java b/OWASP DATASET/BenchmarkTest02387.java new file mode 100644 index 0000000000000000000000000000000000000000..2f2a6c2e561c5477f2c240e4c872af75a453c426 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02387.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02387") +public class BenchmarkTest02387 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02387"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map70399 = new java.util.HashMap(); + map70399.put("keyA-70399", "a-Value"); // put some stuff in the collection + map70399.put("keyB-70399", param); // put it in a collection + map70399.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map70399.get("keyB-70399"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02388.java b/OWASP DATASET/BenchmarkTest02388.java new file mode 100644 index 0000000000000000000000000000000000000000..51d1b7229562668716306b158861bd6802595182 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02388.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02388") +public class BenchmarkTest02388 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02388"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map94322 = new java.util.HashMap(); + map94322.put("keyA-94322", "a_Value"); // put some stuff in the collection + map94322.put("keyB-94322", param); // put it in a collection + map94322.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map94322.get("keyB-94322"); // get it back out + bar = (String) map94322.get("keyA-94322"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02389.java b/OWASP DATASET/BenchmarkTest02389.java new file mode 100644 index 0000000000000000000000000000000000000000..2d90f6fd87172e11c1ab6706a382bfa0d221e985 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02389.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02389") +public class BenchmarkTest02389 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02389"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-256"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02390.java b/OWASP DATASET/BenchmarkTest02390.java new file mode 100644 index 0000000000000000000000000000000000000000..92d3aecdadf3ed610dc902f54cfb043a61b07184 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02390.java @@ -0,0 +1,128 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02390") +public class BenchmarkTest02390 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02390"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-256"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a73202 = param; // assign + StringBuilder b73202 = new StringBuilder(a73202); // stick in stringbuilder + b73202.append(" SafeStuff"); // append some safe content + b73202.replace( + b73202.length() - "Chars".length(), + b73202.length(), + "Chars"); // replace some of the end content + java.util.HashMap map73202 = new java.util.HashMap(); + map73202.put("key73202", b73202.toString()); // put in a collection + String c73202 = (String) map73202.get("key73202"); // get it back out + String d73202 = c73202.substring(0, c73202.length() - 1); // extract most of it + String e73202 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d73202.getBytes()))); // B64 encode and decode it + String f73202 = e73202.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g73202 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g73202); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02391.java b/OWASP DATASET/BenchmarkTest02391.java new file mode 100644 index 0000000000000000000000000000000000000000..2ac820b0a4e5ea875fcf58231de3311d70809b76 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02391.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02391") +public class BenchmarkTest02391 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02391"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02392.java b/OWASP DATASET/BenchmarkTest02392.java new file mode 100644 index 0000000000000000000000000000000000000000..2adc765cb72a657e637597873f9e516d81ef59e5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02392.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02392") +public class BenchmarkTest02392 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02392"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02393.java b/OWASP DATASET/BenchmarkTest02393.java new file mode 100644 index 0000000000000000000000000000000000000000..874f0e5cf46b8221166eca0daed66d29fa54de01 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02393.java @@ -0,0 +1,132 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02393") +public class BenchmarkTest02393 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02393"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a24492 = param; // assign + StringBuilder b24492 = new StringBuilder(a24492); // stick in stringbuilder + b24492.append(" SafeStuff"); // append some safe content + b24492.replace( + b24492.length() - "Chars".length(), + b24492.length(), + "Chars"); // replace some of the end content + java.util.HashMap map24492 = new java.util.HashMap(); + map24492.put("key24492", b24492.toString()); // put in a collection + String c24492 = (String) map24492.get("key24492"); // get it back out + String d24492 = c24492.substring(0, c24492.length() - 1); // extract most of it + String e24492 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d24492.getBytes()))); // B64 encode and decode it + String f24492 = e24492.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g24492 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g24492); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02394.java b/OWASP DATASET/BenchmarkTest02394.java new file mode 100644 index 0000000000000000000000000000000000000000..8edd9c86276f93c6bf543ae60824d4bda62bb6de --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02394.java @@ -0,0 +1,62 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02394") +public class BenchmarkTest02394 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02394"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(java.util.Locale.US, bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02395.java b/OWASP DATASET/BenchmarkTest02395.java new file mode 100644 index 0000000000000000000000000000000000000000..affa0d12fc5cbf2e26f88a55a35a5af6c3e4600e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02395.java @@ -0,0 +1,65 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02395") +public class BenchmarkTest02395 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02395"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().format("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02396.java b/OWASP DATASET/BenchmarkTest02396.java new file mode 100644 index 0000000000000000000000000000000000000000..b50959dec52a6e00998b4da3a3bb478e41f9340b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02396.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02396") +public class BenchmarkTest02396 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02396"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a53479 = param; // assign + StringBuilder b53479 = new StringBuilder(a53479); // stick in stringbuilder + b53479.append(" SafeStuff"); // append some safe content + b53479.replace( + b53479.length() - "Chars".length(), + b53479.length(), + "Chars"); // replace some of the end content + java.util.HashMap map53479 = new java.util.HashMap(); + map53479.put("key53479", b53479.toString()); // put in a collection + String c53479 = (String) map53479.get("key53479"); // get it back out + String d53479 = c53479.substring(0, c53479.length() - 1); // extract most of it + String e53479 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d53479.getBytes()))); // B64 encode and decode it + String f53479 = e53479.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f53479); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02397.java b/OWASP DATASET/BenchmarkTest02397.java new file mode 100644 index 0000000000000000000000000000000000000000..c558e7e25968637aab7c96b0e0b4a0804b05f3ba --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02397.java @@ -0,0 +1,65 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02397") +public class BenchmarkTest02397 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02397"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02398.java b/OWASP DATASET/BenchmarkTest02398.java new file mode 100644 index 0000000000000000000000000000000000000000..b537ab035ab64f838077656db88be6a5b19ba0fb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02398.java @@ -0,0 +1,61 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02398") +public class BenchmarkTest02398 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02398"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02399.java b/OWASP DATASET/BenchmarkTest02399.java new file mode 100644 index 0000000000000000000000000000000000000000..f5a9979585a5d7a0fb4a8fbe787bc045e071b060 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02399.java @@ -0,0 +1,80 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02399") +public class BenchmarkTest02399 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02399"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02400.java b/OWASP DATASET/BenchmarkTest02400.java new file mode 100644 index 0000000000000000000000000000000000000000..c7b079da5fb23caf71d78e44390bcfc4b40c5568 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02400.java @@ -0,0 +1,63 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02400") +public class BenchmarkTest02400 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02400"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02401.java b/OWASP DATASET/BenchmarkTest02401.java new file mode 100644 index 0000000000000000000000000000000000000000..831cb5bf728636419a682c10eb744341835c6eeb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02401.java @@ -0,0 +1,62 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02401") +public class BenchmarkTest02401 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02401"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02402.java b/OWASP DATASET/BenchmarkTest02402.java new file mode 100644 index 0000000000000000000000000000000000000000..08aef2fb3e08fda55dd8fb425d7a06af81a7b50c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02402.java @@ -0,0 +1,67 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02402") +public class BenchmarkTest02402 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02402"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(java.util.Locale.US, bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map55396 = new java.util.HashMap(); + map55396.put("keyA-55396", "a-Value"); // put some stuff in the collection + map55396.put("keyB-55396", param); // put it in a collection + map55396.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map55396.get("keyB-55396"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02403.java b/OWASP DATASET/BenchmarkTest02403.java new file mode 100644 index 0000000000000000000000000000000000000000..c3ce2a02ffe5a5fd4d4367490ec7001460113b9e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02403.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02403") +public class BenchmarkTest02403 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02403"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(java.util.Locale.US, bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a34270 = param; // assign + StringBuilder b34270 = new StringBuilder(a34270); // stick in stringbuilder + b34270.append(" SafeStuff"); // append some safe content + b34270.replace( + b34270.length() - "Chars".length(), + b34270.length(), + "Chars"); // replace some of the end content + java.util.HashMap map34270 = new java.util.HashMap(); + map34270.put("key34270", b34270.toString()); // put in a collection + String c34270 = (String) map34270.get("key34270"); // get it back out + String d34270 = c34270.substring(0, c34270.length() - 1); // extract most of it + String e34270 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d34270.getBytes()))); // B64 encode and decode it + String f34270 = e34270.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f34270); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02404.java b/OWASP DATASET/BenchmarkTest02404.java new file mode 100644 index 0000000000000000000000000000000000000000..3904be4f05493638912369ae122a21f106ef1ff2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02404.java @@ -0,0 +1,67 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02404") +public class BenchmarkTest02404 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02404"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(java.util.Locale.US, bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02405.java b/OWASP DATASET/BenchmarkTest02405.java new file mode 100644 index 0000000000000000000000000000000000000000..e9b1d53b474ed07056dfcfb8a4fac953af31b27d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02405.java @@ -0,0 +1,63 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02405") +public class BenchmarkTest02405 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02405"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar.toCharArray()); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02406.java b/OWASP DATASET/BenchmarkTest02406.java new file mode 100644 index 0000000000000000000000000000000000000000..3bc41302eb8d6169fc5198b77df6d28bee9dffcd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02406.java @@ -0,0 +1,66 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02406") +public class BenchmarkTest02406 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02406"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02407.java b/OWASP DATASET/BenchmarkTest02407.java new file mode 100644 index 0000000000000000000000000000000000000000..729228371ac271bb03833249e3cf3f95cf060b2b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02407.java @@ -0,0 +1,65 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02407") +public class BenchmarkTest02407 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02407"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz58438 = new StringBuilder(param); + bar = sbxyz58438.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02408.java b/OWASP DATASET/BenchmarkTest02408.java new file mode 100644 index 0000000000000000000000000000000000000000..85a876205c7a25dcd762fdc4263901c25524ab68 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02408.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02408") +public class BenchmarkTest02408 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02408"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar.toCharArray()); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a67594 = param; // assign + StringBuilder b67594 = new StringBuilder(a67594); // stick in stringbuilder + b67594.append(" SafeStuff"); // append some safe content + b67594.replace( + b67594.length() - "Chars".length(), + b67594.length(), + "Chars"); // replace some of the end content + java.util.HashMap map67594 = new java.util.HashMap(); + map67594.put("key67594", b67594.toString()); // put in a collection + String c67594 = (String) map67594.get("key67594"); // get it back out + String d67594 = c67594.substring(0, c67594.length() - 1); // extract most of it + String e67594 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d67594.getBytes()))); // B64 encode and decode it + String f67594 = e67594.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g67594 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g67594); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02409.java b/OWASP DATASET/BenchmarkTest02409.java new file mode 100644 index 0000000000000000000000000000000000000000..0cd3615559c194dc8f7f4ec9d1509bb92b377dc1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02409.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02409") +public class BenchmarkTest02409 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02409"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar, 0, length); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02410.java b/OWASP DATASET/BenchmarkTest02410.java new file mode 100644 index 0000000000000000000000000000000000000000..ec5cb4e1ddf0409984f6a37cad2f8e1f73fc9895 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02410.java @@ -0,0 +1,66 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02410") +public class BenchmarkTest02410 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02410"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar, 0, length); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz69687 = new StringBuilder(param); + String bar = sbxyz69687.append("_SafeStuff").toString(); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02411.java b/OWASP DATASET/BenchmarkTest02411.java new file mode 100644 index 0000000000000000000000000000000000000000..8237d87e19c8873890fbba3848ea0c9551fa246f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02411.java @@ -0,0 +1,93 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02411") +public class BenchmarkTest02411 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02411"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String a1 = ""; + String a2 = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + } else { + a1 = "sh"; + a2 = "-c"; + } + String[] args = {a1, a2, "echo " + bar}; + + ProcessBuilder pb = new ProcessBuilder(); + + pb.command(args); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02412.java b/OWASP DATASET/BenchmarkTest02412.java new file mode 100644 index 0000000000000000000000000000000000000000..355b3d0994c67539fb06e0b4cc8941528d44ba96 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02412.java @@ -0,0 +1,90 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02412") +public class BenchmarkTest02412 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02412"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String a1 = ""; + String a2 = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + } else { + a1 = "sh"; + a2 = "-c"; + } + String[] args = {a1, a2, "echo " + bar}; + + ProcessBuilder pb = new ProcessBuilder(); + + pb.command(args); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02413.java b/OWASP DATASET/BenchmarkTest02413.java new file mode 100644 index 0000000000000000000000000000000000000000..24068999bc25f0aaa0f522f59ac24d184bf9f98b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02413.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02413") +public class BenchmarkTest02413 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02413"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String a1 = ""; + String a2 = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + } else { + a1 = "sh"; + a2 = "-c"; + } + String[] args = {a1, a2, "echo " + bar}; + + ProcessBuilder pb = new ProcessBuilder(); + + pb.command(args); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02414.java b/OWASP DATASET/BenchmarkTest02414.java new file mode 100644 index 0000000000000000000000000000000000000000..ac37a716a8ea578abc915d1d061a242bb093495a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02414.java @@ -0,0 +1,100 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02414") +public class BenchmarkTest02414 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02414"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02415.java b/OWASP DATASET/BenchmarkTest02415.java new file mode 100644 index 0000000000000000000000000000000000000000..69446e386a3b3dad071ca0c85ab533a1c34c9313 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02415.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02415") +public class BenchmarkTest02415 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02415"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + byte[] bytes = new byte[10]; + new java.util.Random().nextBytes(bytes); + String rememberMeKey = org.owasp.esapi.ESAPI.encoder().encodeForBase64(bytes, true); + + String user = "Byron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextBytes() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02416.java b/OWASP DATASET/BenchmarkTest02416.java new file mode 100644 index 0000000000000000000000000000000000000000..dc15c5f2860d65eed93092362db65ce4adb93880 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02416.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02416") +public class BenchmarkTest02416 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02416"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + double value = new java.util.Random().nextDouble(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Donna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map59148 = new java.util.HashMap(); + map59148.put("keyA-59148", "a_Value"); // put some stuff in the collection + map59148.put("keyB-59148", param); // put it in a collection + map59148.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map59148.get("keyB-59148"); // get it back out + bar = (String) map59148.get("keyA-59148"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02417.java b/OWASP DATASET/BenchmarkTest02417.java new file mode 100644 index 0000000000000000000000000000000000000000..6d48908255516d524d69a2cce001b49285115413 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02417.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02417") +public class BenchmarkTest02417 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02417"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + double value = new java.util.Random().nextDouble(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Donna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02418.java b/OWASP DATASET/BenchmarkTest02418.java new file mode 100644 index 0000000000000000000000000000000000000000..9bd7566d4f61d8e82d4e117e701cc3dc45fa4450 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02418.java @@ -0,0 +1,126 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02418") +public class BenchmarkTest02418 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02418"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + double value = new java.util.Random().nextDouble(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Donna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02419.java b/OWASP DATASET/BenchmarkTest02419.java new file mode 100644 index 0000000000000000000000000000000000000000..72d9742e5ea5e2a908917e3c48c1ff45f24f2c0d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02419.java @@ -0,0 +1,128 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02419") +public class BenchmarkTest02419 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02419"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + float rand = new java.util.Random().nextFloat(); + String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "Floyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a8935 = param; // assign + StringBuilder b8935 = new StringBuilder(a8935); // stick in stringbuilder + b8935.append(" SafeStuff"); // append some safe content + b8935.replace( + b8935.length() - "Chars".length(), + b8935.length(), + "Chars"); // replace some of the end content + java.util.HashMap map8935 = new java.util.HashMap(); + map8935.put("key8935", b8935.toString()); // put in a collection + String c8935 = (String) map8935.get("key8935"); // get it back out + String d8935 = c8935.substring(0, c8935.length() - 1); // extract most of it + String e8935 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d8935.getBytes()))); // B64 encode and decode it + String f8935 = e8935.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g8935 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g8935); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02420.java b/OWASP DATASET/BenchmarkTest02420.java new file mode 100644 index 0000000000000000000000000000000000000000..3fdffedda3ab6b917ba231a2ed3a3d0163703139 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02420.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02420") +public class BenchmarkTest02420 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02420"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + double stuff = new java.util.Random().nextGaussian(); + String rememberMeKey = Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "Gayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter() + .println("Weak Randomness Test java.util.Random.nextGaussian() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02421.java b/OWASP DATASET/BenchmarkTest02421.java new file mode 100644 index 0000000000000000000000000000000000000000..403c7b37775a2fa60abca68f21caef0f9313ea92 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02421.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02421") +public class BenchmarkTest02421 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02421"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + double stuff = new java.util.Random().nextGaussian(); + String rememberMeKey = Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "Gayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter() + .println("Weak Randomness Test java.util.Random.nextGaussian() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map85191 = new java.util.HashMap(); + map85191.put("keyA-85191", "a_Value"); // put some stuff in the collection + map85191.put("keyB-85191", param); // put it in a collection + map85191.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map85191.get("keyB-85191"); // get it back out + bar = (String) map85191.get("keyA-85191"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02422.java b/OWASP DATASET/BenchmarkTest02422.java new file mode 100644 index 0000000000000000000000000000000000000000..e3480def279fae08743342ab16f8c52ef665b1f3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02422.java @@ -0,0 +1,126 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02422") +public class BenchmarkTest02422 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02422"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + double stuff = new java.util.Random().nextGaussian(); + String rememberMeKey = Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "Gayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter() + .println("Weak Randomness Test java.util.Random.nextGaussian() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02423.java b/OWASP DATASET/BenchmarkTest02423.java new file mode 100644 index 0000000000000000000000000000000000000000..3276b07ebf88d8e994607fdf34df337c292d9974 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02423.java @@ -0,0 +1,126 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02423") +public class BenchmarkTest02423 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02423"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + int randNumber = new java.util.Random().nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "Inga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt(int) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a24134 = param; // assign + StringBuilder b24134 = new StringBuilder(a24134); // stick in stringbuilder + b24134.append(" SafeStuff"); // append some safe content + b24134.replace( + b24134.length() - "Chars".length(), + b24134.length(), + "Chars"); // replace some of the end content + java.util.HashMap map24134 = new java.util.HashMap(); + map24134.put("key24134", b24134.toString()); // put in a collection + String c24134 = (String) map24134.get("key24134"); // get it back out + String d24134 = c24134.substring(0, c24134.length() - 1); // extract most of it + String e24134 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d24134.getBytes()))); // B64 encode and decode it + String f24134 = e24134.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f24134); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02424.java b/OWASP DATASET/BenchmarkTest02424.java new file mode 100644 index 0000000000000000000000000000000000000000..387c62b178cd6dfdead6e92a92227de4757d6614 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02424.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02424") +public class BenchmarkTest02424 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02424"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02425.java b/OWASP DATASET/BenchmarkTest02425.java new file mode 100644 index 0000000000000000000000000000000000000000..13cbacc2dfde70b1aa3d2e7fb6969edbf8815e84 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02425.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02425") +public class BenchmarkTest02425 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02425"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02426.java b/OWASP DATASET/BenchmarkTest02426.java new file mode 100644 index 0000000000000000000000000000000000000000..42b3b1c7c4ef4cd2d289b2adfa990f71cb916ce5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02426.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02426") +public class BenchmarkTest02426 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02426"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02427.java b/OWASP DATASET/BenchmarkTest02427.java new file mode 100644 index 0000000000000000000000000000000000000000..185efe965422091c0b7ea463d22ecfdf39de9902 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02427.java @@ -0,0 +1,90 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest02427") +public class BenchmarkTest02427 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02427"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02428.java b/OWASP DATASET/BenchmarkTest02428.java new file mode 100644 index 0000000000000000000000000000000000000000..93fd5f08ebcd4f149b0c3c4bc6e9ab9898a89b16 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02428.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02428") +public class BenchmarkTest02428 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02428"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String cmd = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd + bar); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map52815 = new java.util.HashMap(); + map52815.put("keyA-52815", "a_Value"); // put some stuff in the collection + map52815.put("keyB-52815", param); // put it in a collection + map52815.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map52815.get("keyB-52815"); // get it back out + bar = (String) map52815.get("keyA-52815"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02429.java b/OWASP DATASET/BenchmarkTest02429.java new file mode 100644 index 0000000000000000000000000000000000000000..df56e600c0d6052ca3bc45dabcab0f505ab18829 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02429.java @@ -0,0 +1,90 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02429") +public class BenchmarkTest02429 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02429"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("echo"); + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ping -c1 "); + args = new String[] {a1, a2, cmd + bar}; + } + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02430.java b/OWASP DATASET/BenchmarkTest02430.java new file mode 100644 index 0000000000000000000000000000000000000000..2ac6ae6a57d07d6b2b73d5970e5d2d062f0feeb5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02430.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02430") +public class BenchmarkTest02430 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02430"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02431.java b/OWASP DATASET/BenchmarkTest02431.java new file mode 100644 index 0000000000000000000000000000000000000000..89de45a3f5767f3e7c9463b6ac07607f5096731a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02431.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02431") +public class BenchmarkTest02431 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02431"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map58889 = new java.util.HashMap(); + map58889.put("keyA-58889", "a-Value"); // put some stuff in the collection + map58889.put("keyB-58889", param); // put it in a collection + map58889.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map58889.get("keyB-58889"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02432.java b/OWASP DATASET/BenchmarkTest02432.java new file mode 100644 index 0000000000000000000000000000000000000000..164a63ecd3bc389c2823e5ed292543a3f2ee5ccd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02432.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02432") +public class BenchmarkTest02432 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02432"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map15850 = new java.util.HashMap(); + map15850.put("keyA-15850", "a-Value"); // put some stuff in the collection + map15850.put("keyB-15850", param); // put it in a collection + map15850.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map15850.get("keyB-15850"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02433.java b/OWASP DATASET/BenchmarkTest02433.java new file mode 100644 index 0000000000000000000000000000000000000000..d2e0fdd3117986b3926bcaea8683dd804f0ba5ba --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02433.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02433") +public class BenchmarkTest02433 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02433"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02434.java b/OWASP DATASET/BenchmarkTest02434.java new file mode 100644 index 0000000000000000000000000000000000000000..eab0d5b7ee87bc56f2c1a0784580074b4f9f357f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02434.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02434") +public class BenchmarkTest02434 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02434"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + getNextNumber(numGen, randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeBystander"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + void getNextNumber(java.util.Random generator, byte[] barray) { + generator.nextBytes(barray); + } + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map29737 = new java.util.HashMap(); + map29737.put("keyA-29737", "a-Value"); // put some stuff in the collection + map29737.put("keyB-29737", param); // put it in a collection + map29737.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map29737.get("keyB-29737"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02435.java b/OWASP DATASET/BenchmarkTest02435.java new file mode 100644 index 0000000000000000000000000000000000000000..0b1d2d975393593d013f0f85c14b4ae3faf0e110 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02435.java @@ -0,0 +1,126 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02435") +public class BenchmarkTest02435 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02435"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + getNextNumber(numGen, randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeBystander"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + void getNextNumber(java.util.Random generator, byte[] barray) { + generator.nextBytes(barray); + } + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02436.java b/OWASP DATASET/BenchmarkTest02436.java new file mode 100644 index 0000000000000000000000000000000000000000..714421b1b80c932c94a464ec1323f0954fdc25b7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02436.java @@ -0,0 +1,122 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02436") +public class BenchmarkTest02436 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02436"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02437.java b/OWASP DATASET/BenchmarkTest02437.java new file mode 100644 index 0000000000000000000000000000000000000000..45bd3e5af4cc754fc31d2117b259b62e2af5b10b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02437.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02437") +public class BenchmarkTest02437 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02437"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02438.java b/OWASP DATASET/BenchmarkTest02438.java new file mode 100644 index 0000000000000000000000000000000000000000..4f0c97e2ff97279a86d6a8b19e4a8b8c0d9e260d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02438.java @@ -0,0 +1,134 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02438") +public class BenchmarkTest02438 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02438"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02439.java b/OWASP DATASET/BenchmarkTest02439.java new file mode 100644 index 0000000000000000000000000000000000000000..f07bbc5e93495f0a34db8e338637f3133d7d6695 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02439.java @@ -0,0 +1,140 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02439") +public class BenchmarkTest02439 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02439"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02440.java b/OWASP DATASET/BenchmarkTest02440.java new file mode 100644 index 0000000000000000000000000000000000000000..6844a49822e2449ee23493b349e06f467e4e3eb9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02440.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02440") +public class BenchmarkTest02440 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02440"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + double stuff = java.security.SecureRandom.getInstance("SHA1PRNG").nextGaussian(); + String rememberMeKey = + Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "SafeGayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextGaussian() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextGaussian() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map85251 = new java.util.HashMap(); + map85251.put("keyA-85251", "a_Value"); // put some stuff in the collection + map85251.put("keyB-85251", param); // put it in a collection + map85251.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map85251.get("keyB-85251"); // get it back out + bar = (String) map85251.get("keyA-85251"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02441.java b/OWASP DATASET/BenchmarkTest02441.java new file mode 100644 index 0000000000000000000000000000000000000000..8b8933e5fd607f83f344cf1532b327626972d05e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02441.java @@ -0,0 +1,118 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02441") +public class BenchmarkTest02441 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02441"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + double stuff = java.security.SecureRandom.getInstance("SHA1PRNG").nextGaussian(); + String rememberMeKey = + Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "SafeGayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextGaussian() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextGaussian() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02442.java b/OWASP DATASET/BenchmarkTest02442.java new file mode 100644 index 0000000000000000000000000000000000000000..996ba59336c2613bbf20cf4add83526a1812e56a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02442.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02442") +public class BenchmarkTest02442 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02442"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + double stuff = java.security.SecureRandom.getInstance("SHA1PRNG").nextGaussian(); + String rememberMeKey = + Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "SafeGayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextGaussian() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextGaussian() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz18041 = new StringBuilder(param); + bar = sbxyz18041.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02443.java b/OWASP DATASET/BenchmarkTest02443.java new file mode 100644 index 0000000000000000000000000000000000000000..eb37b8aab3bef7fc20a4d5c5137ed0be8cba148b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02443.java @@ -0,0 +1,118 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02443") +public class BenchmarkTest02443 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02443"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + double stuff = java.security.SecureRandom.getInstance("SHA1PRNG").nextGaussian(); + String rememberMeKey = + Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "SafeGayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextGaussian() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextGaussian() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02444.java b/OWASP DATASET/BenchmarkTest02444.java new file mode 100644 index 0000000000000000000000000000000000000000..26e9d43edeabf408b32c788afd9eb2fa40d28af7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02444.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02444") +public class BenchmarkTest02444 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02444"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + int randNumber = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "SafeInga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt(int) - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt(int) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02445.java b/OWASP DATASET/BenchmarkTest02445.java new file mode 100644 index 0000000000000000000000000000000000000000..c446715a0f50f05398a2c2bcfec16013423df391 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02445.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02445") +public class BenchmarkTest02445 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02445"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + int randNumber = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "SafeInga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt(int) - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt(int) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02446.java b/OWASP DATASET/BenchmarkTest02446.java new file mode 100644 index 0000000000000000000000000000000000000000..a4556a61ea1ce095da4caa2467f9e1c2c3dd5606 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02446.java @@ -0,0 +1,72 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest02446") +public class BenchmarkTest02446 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02446"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String^,java.lang.Object) + request.getSession().putValue(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: 10340 saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02447.java b/OWASP DATASET/BenchmarkTest02447.java new file mode 100644 index 0000000000000000000000000000000000000000..7897f687432bc09464ed0444d60d296b6d7181fe --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02447.java @@ -0,0 +1,72 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest02447") +public class BenchmarkTest02447 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02447"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02448.java b/OWASP DATASET/BenchmarkTest02448.java new file mode 100644 index 0000000000000000000000000000000000000000..22e33c78d77e9921f01672e5da832b84bc972aa8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02448.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest02448") +public class BenchmarkTest02448 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02448"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String^,java.lang.Object) + request.getSession().setAttribute(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: '10340' saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02449.java b/OWASP DATASET/BenchmarkTest02449.java new file mode 100644 index 0000000000000000000000000000000000000000..c2e222c3026d709784add23e48c41aef9b5a435a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02449.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02449") +public class BenchmarkTest02449 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02449"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02450.java b/OWASP DATASET/BenchmarkTest02450.java new file mode 100644 index 0000000000000000000000000000000000000000..dfe1e414bacbb6cc458ed1f028bf71fb8f2d26b2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02450.java @@ -0,0 +1,80 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02450") +public class BenchmarkTest02450 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02450"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02451.java b/OWASP DATASET/BenchmarkTest02451.java new file mode 100644 index 0000000000000000000000000000000000000000..40b3946c5b6a2431ac69e519a1e4ce15d213597c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02451.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02451") +public class BenchmarkTest02451 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02451"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.execute(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring execute method doesn't return results."); + + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02452.java b/OWASP DATASET/BenchmarkTest02452.java new file mode 100644 index 0000000000000000000000000000000000000000..5aab2d2441c1046db91cea162c2561a57318a76f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02452.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02452") +public class BenchmarkTest02452 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02452"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List> list = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForList(sql); + response.getWriter().println("Your results are:
"); + + // System.out.println("Your results are"); + + for (Object o : list) { + response.getWriter() + .println( + org.owasp.esapi.ESAPI.encoder().encodeForHTML(o.toString()) + + "
"); + // System.out.println(o.toString()); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a91263 = param; // assign + StringBuilder b91263 = new StringBuilder(a91263); // stick in stringbuilder + b91263.append(" SafeStuff"); // append some safe content + b91263.replace( + b91263.length() - "Chars".length(), + b91263.length(), + "Chars"); // replace some of the end content + java.util.HashMap map91263 = new java.util.HashMap(); + map91263.put("key91263", b91263.toString()); // put in a collection + String c91263 = (String) map91263.get("key91263"); // get it back out + String d91263 = c91263.substring(0, c91263.length() - 1); // extract most of it + String e91263 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d91263.getBytes()))); // B64 encode and decode it + String f91263 = e91263.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g91263 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g91263); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02453.java b/OWASP DATASET/BenchmarkTest02453.java new file mode 100644 index 0000000000000000000000000000000000000000..cb34a8382e019405363813e60a4071194c35608e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02453.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02453") +public class BenchmarkTest02453 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02453"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String sql = + "SELECT TOP 1 userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.Map results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForMap(sql); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(results.toString())); + // System.out.println(results.toString()); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02454.java b/OWASP DATASET/BenchmarkTest02454.java new file mode 100644 index 0000000000000000000000000000000000000000..69d1bbba6c1e283381d44a2d656ccb63c3dea321 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02454.java @@ -0,0 +1,73 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02454") +public class BenchmarkTest02454 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02454"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.addBatch(sql); + int[] counts = statement.executeBatch(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(sql, counts, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02455.java b/OWASP DATASET/BenchmarkTest02455.java new file mode 100644 index 0000000000000000000000000000000000000000..bcdb016a48090d35fb9d0b0cd5416c78a1163a08 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02455.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02455") +public class BenchmarkTest02455 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02455"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02456.java b/OWASP DATASET/BenchmarkTest02456.java new file mode 100644 index 0000000000000000000000000000000000000000..bfdbb132da1a6433fb9220aec68f219b8d599b34 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02456.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02456") +public class BenchmarkTest02456 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02456"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new String[] {"USERNAME", "PASSWORD"}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02457.java b/OWASP DATASET/BenchmarkTest02457.java new file mode 100644 index 0000000000000000000000000000000000000000..923a2039f42b442c3bcff197c8afbc03ddbc014b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02457.java @@ -0,0 +1,98 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xpathi-00/BenchmarkTest02457") +public class BenchmarkTest02457 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheParameter("BenchmarkTest02457"); + if (param == null) param = ""; + + String bar = doSomething(request, param); + + try { + java.io.FileInputStream file = + new java.io.FileInputStream( + org.owasp.benchmark.helpers.Utils.getFileFromClasspath( + "employees.xml", this.getClass().getClassLoader())); + javax.xml.parsers.DocumentBuilderFactory builderFactory = + javax.xml.parsers.DocumentBuilderFactory.newInstance(); + // Prevent XXE + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + javax.xml.parsers.DocumentBuilder builder = builderFactory.newDocumentBuilder(); + org.w3c.dom.Document xmlDocument = builder.parse(file); + javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance(); + javax.xml.xpath.XPath xp = xpf.newXPath(); + + String expression = "/Employees/Employee[@emplid='" + bar + "']"; + String result = xp.evaluate(expression, xmlDocument); + + response.getWriter().println("Your query results are: " + result + "
"); + + } catch (javax.xml.xpath.XPathExpressionException + | javax.xml.parsers.ParserConfigurationException + | org.xml.sax.SAXException e) { + response.getWriter() + .println( + "Error parsing XPath input: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(bar) + + "'"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02458.java b/OWASP DATASET/BenchmarkTest02458.java new file mode 100644 index 0000000000000000000000000000000000000000..daf677aac52cfddc922e17434c6499ae3159294c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02458.java @@ -0,0 +1,165 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02458") +public class BenchmarkTest02458 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02458"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "DES/CBC/PKCS5PADDING", java.security.Security.getProvider("SunJCE")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02459.java b/OWASP DATASET/BenchmarkTest02459.java new file mode 100644 index 0000000000000000000000000000000000000000..a47a0e79bfdd40c5ea02904a7f9323a10348f7e1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02459.java @@ -0,0 +1,164 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02459") +public class BenchmarkTest02459 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02459"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map56716 = new java.util.HashMap(); + map56716.put("keyA-56716", "a-Value"); // put some stuff in the collection + map56716.put("keyB-56716", param); // put it in a collection + map56716.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map56716.get("keyB-56716"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02460.java b/OWASP DATASET/BenchmarkTest02460.java new file mode 100644 index 0000000000000000000000000000000000000000..b5a0ee5481f8eddfe1a95d5d128d47a1c52ca4a7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02460.java @@ -0,0 +1,178 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02460") +public class BenchmarkTest02460 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02460"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02461.java b/OWASP DATASET/BenchmarkTest02461.java new file mode 100644 index 0000000000000000000000000000000000000000..d40524db90693bd6f04ed5e3ddb2f525880c3d61 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02461.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02461") +public class BenchmarkTest02461 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02461"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "AES/CCM/NoPadding", java.security.Security.getProvider("BC")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02462.java b/OWASP DATASET/BenchmarkTest02462.java new file mode 100644 index 0000000000000000000000000000000000000000..6b3984e33ee3eb962bc69f2f1d3940e863dd4fad --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02462.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02462") +public class BenchmarkTest02462 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02462"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02463.java b/OWASP DATASET/BenchmarkTest02463.java new file mode 100644 index 0000000000000000000000000000000000000000..f2f0b07cac0d874046c91f09166785ff81636c48 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02463.java @@ -0,0 +1,80 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02463") +public class BenchmarkTest02463 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02463"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + java.io.File fileTarget = + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR, bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02464.java b/OWASP DATASET/BenchmarkTest02464.java new file mode 100644 index 0000000000000000000000000000000000000000..ca7d8c33e1c8e25a791974e85fd05bb190167c76 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02464.java @@ -0,0 +1,93 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02464") +public class BenchmarkTest02464 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02464"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + java.io.File fileTarget = new java.io.File(bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02465.java b/OWASP DATASET/BenchmarkTest02465.java new file mode 100644 index 0000000000000000000000000000000000000000..5aa56319d400fc10934cbeb8e4713d4174f8aa5e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02465.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02465") +public class BenchmarkTest02465 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02465"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(new java.io.File(fileName)); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting FileInputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02466.java b/OWASP DATASET/BenchmarkTest02466.java new file mode 100644 index 0000000000000000000000000000000000000000..38439237a8df42436b0612ef7f9515836d758e64 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02466.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-02/BenchmarkTest02466") +public class BenchmarkTest02466 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02466"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(new java.io.File(fileName)); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting FileInputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02467.java b/OWASP DATASET/BenchmarkTest02467.java new file mode 100644 index 0000000000000000000000000000000000000000..7b2fa26d62431ff59d6ac9f149b424ac4a91a726 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02467.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-03/BenchmarkTest02467") +public class BenchmarkTest02467 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02467"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(fileName); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a60326 = param; // assign + StringBuilder b60326 = new StringBuilder(a60326); // stick in stringbuilder + b60326.append(" SafeStuff"); // append some safe content + b60326.replace( + b60326.length() - "Chars".length(), + b60326.length(), + "Chars"); // replace some of the end content + java.util.HashMap map60326 = new java.util.HashMap(); + map60326.put("key60326", b60326.toString()); // put in a collection + String c60326 = (String) map60326.get("key60326"); // get it back out + String d60326 = c60326.substring(0, c60326.length() - 1); // extract most of it + String e60326 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d60326.getBytes()))); // B64 encode and decode it + String f60326 = e60326.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g60326 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g60326); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02468.java b/OWASP DATASET/BenchmarkTest02468.java new file mode 100644 index 0000000000000000000000000000000000000000..9b962010ae94802999e1de31dcc23b29d1f2592f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02468.java @@ -0,0 +1,90 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-03/BenchmarkTest02468") +public class BenchmarkTest02468 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02468"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + try ( + // Create the file first so the test won't throw an exception if it doesn't exist. + // Note: Don't actually do this because this method signature could cause a tool to find + // THIS file constructor + // as a vuln, rather than the File signature we are trying to actually test. + // If necessary, just run the benchmark twice. The 1st run should create all the necessary + // files. + // new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar).createNewFile(); + + java.io.FileOutputStream fos = + new java.io.FileOutputStream(new java.io.FileInputStream(fileName).getFD()); ) { + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02469.java b/OWASP DATASET/BenchmarkTest02469.java new file mode 100644 index 0000000000000000000000000000000000000000..11012b92ad7b19a383846d6917d844a9604a7599 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02469.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-03/BenchmarkTest02469") +public class BenchmarkTest02469 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02469"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName, false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02470.java b/OWASP DATASET/BenchmarkTest02470.java new file mode 100644 index 0000000000000000000000000000000000000000..e5321427a04e272d4f6825b39542656327ae561a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02470.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-03/BenchmarkTest02470") +public class BenchmarkTest02470 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02470"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName, false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02471.java b/OWASP DATASET/BenchmarkTest02471.java new file mode 100644 index 0000000000000000000000000000000000000000..9755a48c3d9be51aab5b1ba1781c077ef03ceb83 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02471.java @@ -0,0 +1,100 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-03/BenchmarkTest02471") +public class BenchmarkTest02471 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02471"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + java.io.InputStream is = null; + + try { + java.nio.file.Path path = java.nio.file.Paths.get(fileName); + is = java.nio.file.Files.newInputStream(path, java.nio.file.StandardOpenOption.READ); + byte[] b = new byte[1000]; + int size = is.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + is.close(); + } catch (Exception e) { + System.out.println("Couldn't open InputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting InputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (is != null) { + try { + is.close(); + is = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02472.java b/OWASP DATASET/BenchmarkTest02472.java new file mode 100644 index 0000000000000000000000000000000000000000..c36b45758740a8fd0c3f7edf4a516105e94b4953 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02472.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest02472") +public class BenchmarkTest02472 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02472"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + bar + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + + javax.naming.directory.DirContext ctx = ads.getDirContext(); + javax.naming.directory.InitialDirContext idc = + (javax.naming.directory.InitialDirContext) ctx; + boolean found = false; + javax.naming.NamingEnumeration results = + idc.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02473.java b/OWASP DATASET/BenchmarkTest02473.java new file mode 100644 index 0000000000000000000000000000000000000000..059334a5f9e940eda91ad7f49fbf3b06bb1e6855 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02473.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02473") +public class BenchmarkTest02473 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02473"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + double value = java.lang.Math.random(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Doug"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + response.getWriter().println("Weak Randomness Test java.lang.Math.random() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map91880 = new java.util.HashMap(); + map91880.put("keyA-91880", "a-Value"); // put some stuff in the collection + map91880.put("keyB-91880", param); // put it in a collection + map91880.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map91880.get("keyB-91880"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02474.java b/OWASP DATASET/BenchmarkTest02474.java new file mode 100644 index 0000000000000000000000000000000000000000..93664716d5499b9ab6abf45d4dfbe337b66df288 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02474.java @@ -0,0 +1,122 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02474") +public class BenchmarkTest02474 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02474"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02475.java b/OWASP DATASET/BenchmarkTest02475.java new file mode 100644 index 0000000000000000000000000000000000000000..21470f1025f34b83c3604c4070c597914fb1cbe0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02475.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02475") +public class BenchmarkTest02475 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02475"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map43776 = new java.util.HashMap(); + map43776.put("keyA-43776", "a-Value"); // put some stuff in the collection + map43776.put("keyB-43776", param); // put it in a collection + map43776.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map43776.get("keyB-43776"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02476.java b/OWASP DATASET/BenchmarkTest02476.java new file mode 100644 index 0000000000000000000000000000000000000000..115561b6011cd10067ee30283f9ae799f0b085fa --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02476.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02476") +public class BenchmarkTest02476 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02476"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02477.java b/OWASP DATASET/BenchmarkTest02477.java new file mode 100644 index 0000000000000000000000000000000000000000..baff191b4f95c5c0702a2b785c1f3f2f01241666 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02477.java @@ -0,0 +1,128 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02477") +public class BenchmarkTest02477 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02477"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-256"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a40743 = param; // assign + StringBuilder b40743 = new StringBuilder(a40743); // stick in stringbuilder + b40743.append(" SafeStuff"); // append some safe content + b40743.replace( + b40743.length() - "Chars".length(), + b40743.length(), + "Chars"); // replace some of the end content + java.util.HashMap map40743 = new java.util.HashMap(); + map40743.put("key40743", b40743.toString()); // put in a collection + String c40743 = (String) map40743.get("key40743"); // get it back out + String d40743 = c40743.substring(0, c40743.length() - 1); // extract most of it + String e40743 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d40743.getBytes()))); // B64 encode and decode it + String f40743 = e40743.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g40743 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g40743); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02478.java b/OWASP DATASET/BenchmarkTest02478.java new file mode 100644 index 0000000000000000000000000000000000000000..b709c1052c5ef89d64edd6c50c99f104c9a51056 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02478.java @@ -0,0 +1,118 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02478") +public class BenchmarkTest02478 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02478"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02479.java b/OWASP DATASET/BenchmarkTest02479.java new file mode 100644 index 0000000000000000000000000000000000000000..6f14288d5d7515f4b9cd2eea793daeff4066f466 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02479.java @@ -0,0 +1,111 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02479") +public class BenchmarkTest02479 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02479"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02480.java b/OWASP DATASET/BenchmarkTest02480.java new file mode 100644 index 0000000000000000000000000000000000000000..73b0997ba520501631903b0a3470517bcfdc019d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02480.java @@ -0,0 +1,66 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02480") +public class BenchmarkTest02480 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02480"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar.toCharArray()); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02481.java b/OWASP DATASET/BenchmarkTest02481.java new file mode 100644 index 0000000000000000000000000000000000000000..0659a20dbc096035f59091b23a3184cd2c14bdc3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02481.java @@ -0,0 +1,71 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02481") +public class BenchmarkTest02481 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02481"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar.toCharArray()); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02482.java b/OWASP DATASET/BenchmarkTest02482.java new file mode 100644 index 0000000000000000000000000000000000000000..fd109e2cf8ed5bf0af37e2558cba495771cfd355 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02482.java @@ -0,0 +1,80 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02482") +public class BenchmarkTest02482 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02482"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar.toCharArray()); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02483.java b/OWASP DATASET/BenchmarkTest02483.java new file mode 100644 index 0000000000000000000000000000000000000000..1a1ac72911022bc9a5c023d5cb13c94876ebd223 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02483.java @@ -0,0 +1,61 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02483") +public class BenchmarkTest02483 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02483"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02484.java b/OWASP DATASET/BenchmarkTest02484.java new file mode 100644 index 0000000000000000000000000000000000000000..355b3e59bd6024ad65ea44dc5ffb0a32244bbe5e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02484.java @@ -0,0 +1,67 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02484") +public class BenchmarkTest02484 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02484"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map12535 = new java.util.HashMap(); + map12535.put("keyA-12535", "a_Value"); // put some stuff in the collection + map12535.put("keyB-12535", param); // put it in a collection + map12535.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map12535.get("keyB-12535"); // get it back out + bar = (String) map12535.get("keyA-12535"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02485.java b/OWASP DATASET/BenchmarkTest02485.java new file mode 100644 index 0000000000000000000000000000000000000000..a1d628da779dd09a08885b57b9590a0d7e6f6a8c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02485.java @@ -0,0 +1,72 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02485") +public class BenchmarkTest02485 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02485"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02486.java b/OWASP DATASET/BenchmarkTest02486.java new file mode 100644 index 0000000000000000000000000000000000000000..a6827afca80c617926c47c9f4f770ab131d84d83 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02486.java @@ -0,0 +1,66 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-04/BenchmarkTest02486") +public class BenchmarkTest02486 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02486"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz61588 = new StringBuilder(param); + bar = sbxyz61588.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02487.java b/OWASP DATASET/BenchmarkTest02487.java new file mode 100644 index 0000000000000000000000000000000000000000..3549a844f092f1c754dda2698aee09a07a5092fd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02487.java @@ -0,0 +1,64 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02487") +public class BenchmarkTest02487 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02487"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {bar, "b"}; + response.getWriter().printf("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02488.java b/OWASP DATASET/BenchmarkTest02488.java new file mode 100644 index 0000000000000000000000000000000000000000..7a1392869f78668ab7b1b39aa5ad54378f1e11da --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02488.java @@ -0,0 +1,62 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02488") +public class BenchmarkTest02488 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02488"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {bar, "b"}; + response.getWriter().printf("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02489.java b/OWASP DATASET/BenchmarkTest02489.java new file mode 100644 index 0000000000000000000000000000000000000000..41ea6d3203d985c172dd0ab833896c85d7d03127 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02489.java @@ -0,0 +1,62 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02489") +public class BenchmarkTest02489 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02489"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02490.java b/OWASP DATASET/BenchmarkTest02490.java new file mode 100644 index 0000000000000000000000000000000000000000..46d844380a33f315397e0d2343adedc6162d0b49 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02490.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02490") +public class BenchmarkTest02490 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02490"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a28523 = param; // assign + StringBuilder b28523 = new StringBuilder(a28523); // stick in stringbuilder + b28523.append(" SafeStuff"); // append some safe content + b28523.replace( + b28523.length() - "Chars".length(), + b28523.length(), + "Chars"); // replace some of the end content + java.util.HashMap map28523 = new java.util.HashMap(); + map28523.put("key28523", b28523.toString()); // put in a collection + String c28523 = (String) map28523.get("key28523"); // get it back out + String d28523 = c28523.substring(0, c28523.length() - 1); // extract most of it + String e28523 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d28523.getBytes()))); // B64 encode and decode it + String f28523 = e28523.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g28523 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g28523); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02491.java b/OWASP DATASET/BenchmarkTest02491.java new file mode 100644 index 0000000000000000000000000000000000000000..1dc16c4135379d506db56153a0b20a701dc7dd79 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02491.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02491") +public class BenchmarkTest02491 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02491"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar.toCharArray()); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a17852 = param; // assign + StringBuilder b17852 = new StringBuilder(a17852); // stick in stringbuilder + b17852.append(" SafeStuff"); // append some safe content + b17852.replace( + b17852.length() - "Chars".length(), + b17852.length(), + "Chars"); // replace some of the end content + java.util.HashMap map17852 = new java.util.HashMap(); + map17852.put("key17852", b17852.toString()); // put in a collection + String c17852 = (String) map17852.get("key17852"); // get it back out + String d17852 = c17852.substring(0, c17852.length() - 1); // extract most of it + String e17852 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d17852.getBytes()))); // B64 encode and decode it + String f17852 = e17852.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g17852 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g17852); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02492.java b/OWASP DATASET/BenchmarkTest02492.java new file mode 100644 index 0000000000000000000000000000000000000000..f8abe196ea52f68dd4b3096a3c21069bc0922006 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02492.java @@ -0,0 +1,61 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02492") +public class BenchmarkTest02492 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02492"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar.toCharArray()); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02493.java b/OWASP DATASET/BenchmarkTest02493.java new file mode 100644 index 0000000000000000000000000000000000000000..9b2dba86f5671cf0c72096ea8d295b4b5df806fe --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02493.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02493") +public class BenchmarkTest02493 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02493"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar.toCharArray(), 0, length); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map4720 = new java.util.HashMap(); + map4720.put("keyA-4720", "a-Value"); // put some stuff in the collection + map4720.put("keyB-4720", param); // put it in a collection + map4720.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map4720.get("keyB-4720"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02494.java b/OWASP DATASET/BenchmarkTest02494.java new file mode 100644 index 0000000000000000000000000000000000000000..2a9decfa7b8ccd27e3401519c855c0596cfa5ffb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02494.java @@ -0,0 +1,65 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02494") +public class BenchmarkTest02494 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02494"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz57919 = new StringBuilder(param); + bar = sbxyz57919.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02495.java b/OWASP DATASET/BenchmarkTest02495.java new file mode 100644 index 0000000000000000000000000000000000000000..bf6fc7b831a2f689c2793a5af2d427d929c3e8eb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02495.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02495") +public class BenchmarkTest02495 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02495"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar, 0, length); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02496.java b/OWASP DATASET/BenchmarkTest02496.java new file mode 100644 index 0000000000000000000000000000000000000000..63d488edbf2a8e7fd1f2ac65ad5fa399a1b7cb7f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02496.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02496") +public class BenchmarkTest02496 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02496"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String a1 = ""; + String a2 = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + } else { + a1 = "sh"; + a2 = "-c"; + } + String[] args = {a1, a2, "echo " + bar}; + + ProcessBuilder pb = new ProcessBuilder(); + + pb.command(args); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02497.java b/OWASP DATASET/BenchmarkTest02497.java new file mode 100644 index 0000000000000000000000000000000000000000..e2a6093a30ca35bf9f479817beef9153a4c1ea30 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02497.java @@ -0,0 +1,128 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02497") +public class BenchmarkTest02497 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02497"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + double value = new java.util.Random().nextDouble(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Donna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a40533 = param; // assign + StringBuilder b40533 = new StringBuilder(a40533); // stick in stringbuilder + b40533.append(" SafeStuff"); // append some safe content + b40533.replace( + b40533.length() - "Chars".length(), + b40533.length(), + "Chars"); // replace some of the end content + java.util.HashMap map40533 = new java.util.HashMap(); + map40533.put("key40533", b40533.toString()); // put in a collection + String c40533 = (String) map40533.get("key40533"); // get it back out + String d40533 = c40533.substring(0, c40533.length() - 1); // extract most of it + String e40533 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d40533.getBytes()))); // B64 encode and decode it + String f40533 = e40533.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g40533 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g40533); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02498.java b/OWASP DATASET/BenchmarkTest02498.java new file mode 100644 index 0000000000000000000000000000000000000000..cee7ee4e9d6c439ec36a6aebcd4f61ab751f0247 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02498.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02498") +public class BenchmarkTest02498 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02498"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + double value = new java.util.Random().nextDouble(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Donna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02499.java b/OWASP DATASET/BenchmarkTest02499.java new file mode 100644 index 0000000000000000000000000000000000000000..724cbe69501851dafb38d51159207c88c1f849d9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02499.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02499") +public class BenchmarkTest02499 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02499"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + float rand = new java.util.Random().nextFloat(); + String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "Floyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02500.java b/OWASP DATASET/BenchmarkTest02500.java new file mode 100644 index 0000000000000000000000000000000000000000..7da74e90b782474d834ae850827f8660033b9d2c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02500.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02500") +public class BenchmarkTest02500 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02500"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + double stuff = new java.util.Random().nextGaussian(); + String rememberMeKey = Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "Gayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter() + .println("Weak Randomness Test java.util.Random.nextGaussian() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02501.java b/OWASP DATASET/BenchmarkTest02501.java new file mode 100644 index 0000000000000000000000000000000000000000..876a87278390fbb9e5c67d8052289c12b122e048 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02501.java @@ -0,0 +1,111 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02501") +public class BenchmarkTest02501 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02501"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02502.java b/OWASP DATASET/BenchmarkTest02502.java new file mode 100644 index 0000000000000000000000000000000000000000..ed35c871bc630d4596ec8420ee099e98beb7d0ae --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02502.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02502") +public class BenchmarkTest02502 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02502"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02503.java b/OWASP DATASET/BenchmarkTest02503.java new file mode 100644 index 0000000000000000000000000000000000000000..2b9348652cbd0395a1fb0c9ba4c44b57365b029b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02503.java @@ -0,0 +1,127 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02503") +public class BenchmarkTest02503 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02503"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a70407 = param; // assign + StringBuilder b70407 = new StringBuilder(a70407); // stick in stringbuilder + b70407.append(" SafeStuff"); // append some safe content + b70407.replace( + b70407.length() - "Chars".length(), + b70407.length(), + "Chars"); // replace some of the end content + java.util.HashMap map70407 = new java.util.HashMap(); + map70407.put("key70407", b70407.toString()); // put in a collection + String c70407 = (String) map70407.get("key70407"); // get it back out + String d70407 = c70407.substring(0, c70407.length() - 1); // extract most of it + String e70407 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d70407.getBytes()))); // B64 encode and decode it + String f70407 = e70407.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g70407 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g70407); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02504.java b/OWASP DATASET/BenchmarkTest02504.java new file mode 100644 index 0000000000000000000000000000000000000000..120c10407d2c066b73284f21c245627bb848bd71 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02504.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02504") +public class BenchmarkTest02504 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02504"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02505.java b/OWASP DATASET/BenchmarkTest02505.java new file mode 100644 index 0000000000000000000000000000000000000000..39321e150a5275e6b4d3c140e3fa05df1c40196a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02505.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02505") +public class BenchmarkTest02505 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02505"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02506.java b/OWASP DATASET/BenchmarkTest02506.java new file mode 100644 index 0000000000000000000000000000000000000000..a6e9ad86f24c18dfcefbe2da5888a08b1b4c9b06 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02506.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02506") +public class BenchmarkTest02506 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02506"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02507.java b/OWASP DATASET/BenchmarkTest02507.java new file mode 100644 index 0000000000000000000000000000000000000000..7e3a825f8e52db973e006309b2d8d67e779d4a5a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02507.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest02507") +public class BenchmarkTest02507 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02507"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02508.java b/OWASP DATASET/BenchmarkTest02508.java new file mode 100644 index 0000000000000000000000000000000000000000..a2ffa81135d3de06f2551ee87feb1b5d4b6be278 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02508.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest02508") +public class BenchmarkTest02508 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02508"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02509.java b/OWASP DATASET/BenchmarkTest02509.java new file mode 100644 index 0000000000000000000000000000000000000000..3affbf2c3e2366585ba49c50ed2321b1dd14326b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02509.java @@ -0,0 +1,66 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02509") +public class BenchmarkTest02509 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02509"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write("Parameter value: " + bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02510.java b/OWASP DATASET/BenchmarkTest02510.java new file mode 100644 index 0000000000000000000000000000000000000000..7e577e0a558f2982e18b563bd311f54886613548 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02510.java @@ -0,0 +1,97 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02510") +public class BenchmarkTest02510 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02510"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a11776 = param; // assign + StringBuilder b11776 = new StringBuilder(a11776); // stick in stringbuilder + b11776.append(" SafeStuff"); // append some safe content + b11776.replace( + b11776.length() - "Chars".length(), + b11776.length(), + "Chars"); // replace some of the end content + java.util.HashMap map11776 = new java.util.HashMap(); + map11776.put("key11776", b11776.toString()); // put in a collection + String c11776 = (String) map11776.get("key11776"); // get it back out + String d11776 = c11776.substring(0, c11776.length() - 1); // extract most of it + String e11776 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d11776.getBytes()))); // B64 encode and decode it + String f11776 = e11776.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g11776 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g11776); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02511.java b/OWASP DATASET/BenchmarkTest02511.java new file mode 100644 index 0000000000000000000000000000000000000000..d6f3130fc7870a75f2c9eede52c8f195fb077373 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02511.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02511") +public class BenchmarkTest02511 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02511"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02512.java b/OWASP DATASET/BenchmarkTest02512.java new file mode 100644 index 0000000000000000000000000000000000000000..e818eeb35e4e3515d278cafa7c9a99adf4ee147b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02512.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02512") +public class BenchmarkTest02512 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02512"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02513.java b/OWASP DATASET/BenchmarkTest02513.java new file mode 100644 index 0000000000000000000000000000000000000000..7d8b18ade07b47ed077c2d22f9bf2c9255371d5e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02513.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02513") +public class BenchmarkTest02513 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02513"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02514.java b/OWASP DATASET/BenchmarkTest02514.java new file mode 100644 index 0000000000000000000000000000000000000000..23797c90977b2d2e7d7cb12011dd02b57b7ef97c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02514.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02514") +public class BenchmarkTest02514 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02514"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02515.java b/OWASP DATASET/BenchmarkTest02515.java new file mode 100644 index 0000000000000000000000000000000000000000..c871644899756ac25ada0ce4f2d6276931d2ed48 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02515.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02515") +public class BenchmarkTest02515 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02515"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(cmd, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02516.java b/OWASP DATASET/BenchmarkTest02516.java new file mode 100644 index 0000000000000000000000000000000000000000..4212852cb77070266d0019732b33a6929a157df8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02516.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-02/BenchmarkTest02516") +public class BenchmarkTest02516 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02516"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + try { + Process p = r.exec(cmd, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map74796 = new java.util.HashMap(); + map74796.put("keyA-74796", "a-Value"); // put some stuff in the collection + map74796.put("keyB-74796", param); // put it in a collection + map74796.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map74796.get("keyB-74796"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02517.java b/OWASP DATASET/BenchmarkTest02517.java new file mode 100644 index 0000000000000000000000000000000000000000..b9dbf494bfd00f0e5c30d9dac63303b1e06b529b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02517.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-03/BenchmarkTest02517") +public class BenchmarkTest02517 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02517"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + try { + Process p = r.exec(cmd, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02518.java b/OWASP DATASET/BenchmarkTest02518.java new file mode 100644 index 0000000000000000000000000000000000000000..aa6b0ddb66d91b4548c943a2915e3daed28ae7cc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02518.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-03/BenchmarkTest02518") +public class BenchmarkTest02518 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02518"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + try { + Process p = r.exec(cmd, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02519.java b/OWASP DATASET/BenchmarkTest02519.java new file mode 100644 index 0000000000000000000000000000000000000000..bb508fe9837dfb32cd00f69f5a1c616aa15e8906 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02519.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02519") +public class BenchmarkTest02519 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02519"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz84406 = new StringBuilder(param); + bar = sbxyz84406.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02520.java b/OWASP DATASET/BenchmarkTest02520.java new file mode 100644 index 0000000000000000000000000000000000000000..e166890e4c11db3b57f7bb5bdca9243c9cce023c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02520.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02520") +public class BenchmarkTest02520 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02520"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02521.java b/OWASP DATASET/BenchmarkTest02521.java new file mode 100644 index 0000000000000000000000000000000000000000..f0ac559b1c880b1357c295bd5d75e5aa1706f2bf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02521.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02521") +public class BenchmarkTest02521 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02521"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + try { + float rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextFloat(); + String rememberMeKey = + Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeFloyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextFloat() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextFloat() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02522.java b/OWASP DATASET/BenchmarkTest02522.java new file mode 100644 index 0000000000000000000000000000000000000000..83090046542d4c8e2366dfa26acccf08fd3b2428 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02522.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02522") +public class BenchmarkTest02522 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02522"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + try { + int randNumber = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "SafeInga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt(int) - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt(int) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02523.java b/OWASP DATASET/BenchmarkTest02523.java new file mode 100644 index 0000000000000000000000000000000000000000..ec7a2d11061c4ce94ac795f7bf560bf37c1f6d4e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02523.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest02523") +public class BenchmarkTest02523 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02523"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String^,java.lang.Object) + request.getSession().putValue(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: 10340 saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02524.java b/OWASP DATASET/BenchmarkTest02524.java new file mode 100644 index 0000000000000000000000000000000000000000..2366f42a3bdb11bafce6d7a3db15fdd7a6e759f9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02524.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest02524") +public class BenchmarkTest02524 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02524"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02525.java b/OWASP DATASET/BenchmarkTest02525.java new file mode 100644 index 0000000000000000000000000000000000000000..8586793c7e0bc8540fa0222fa5a603ae3cbf0167 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02525.java @@ -0,0 +1,69 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest02525") +public class BenchmarkTest02525 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02525"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02526.java b/OWASP DATASET/BenchmarkTest02526.java new file mode 100644 index 0000000000000000000000000000000000000000..0e126e629e9e15b44be39c1672936660715622c3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02526.java @@ -0,0 +1,67 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest02526") +public class BenchmarkTest02526 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02526"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String,java.lang.Object^) + request.getSession().putValue("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02527.java b/OWASP DATASET/BenchmarkTest02527.java new file mode 100644 index 0000000000000000000000000000000000000000..e17c860febfa8ef7200188b0d198f60149b7c711 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02527.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest02527") +public class BenchmarkTest02527 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02527"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String^,java.lang.Object) + request.getSession().setAttribute(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: '10340' saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02528.java b/OWASP DATASET/BenchmarkTest02528.java new file mode 100644 index 0000000000000000000000000000000000000000..b9e228ab916f7d0af9dbb3bb3bbfa0a45c1764fb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02528.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02528") +public class BenchmarkTest02528 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02528"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = connection.prepareCall(sql); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02529.java b/OWASP DATASET/BenchmarkTest02529.java new file mode 100644 index 0000000000000000000000000000000000000000..1402bf95fb3d97e5ce11c44ba247c05da5896573 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02529.java @@ -0,0 +1,80 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02529") +public class BenchmarkTest02529 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02529"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = connection.prepareCall(sql); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map32022 = new java.util.HashMap(); + map32022.put("keyA-32022", "a_Value"); // put some stuff in the collection + map32022.put("keyB-32022", param); // put it in a collection + map32022.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map32022.get("keyB-32022"); // get it back out + bar = (String) map32022.get("keyA-32022"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02530.java b/OWASP DATASET/BenchmarkTest02530.java new file mode 100644 index 0000000000000000000000000000000000000000..4bce2e6cb7dc5233a098ed6888ddf05e42dfae83 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02530.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02530") +public class BenchmarkTest02530 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02530"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02531.java b/OWASP DATASET/BenchmarkTest02531.java new file mode 100644 index 0000000000000000000000000000000000000000..4b46ee9f66ea5fdabaac1d1960aed5ff64f77032 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02531.java @@ -0,0 +1,80 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02531") +public class BenchmarkTest02531 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02531"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02532.java b/OWASP DATASET/BenchmarkTest02532.java new file mode 100644 index 0000000000000000000000000000000000000000..150e8585e3fc78dcdc8e98646cb7b44f462694f4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02532.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02532") +public class BenchmarkTest02532 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02532"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02533.java b/OWASP DATASET/BenchmarkTest02533.java new file mode 100644 index 0000000000000000000000000000000000000000..cf898883c9c661120b86c10831355bac0cba66eb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02533.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02533") +public class BenchmarkTest02533 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02533"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02534.java b/OWASP DATASET/BenchmarkTest02534.java new file mode 100644 index 0000000000000000000000000000000000000000..e2fceaffed567e1b9d34383705b6aab3220587ab --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02534.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02534") +public class BenchmarkTest02534 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02534"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02535.java b/OWASP DATASET/BenchmarkTest02535.java new file mode 100644 index 0000000000000000000000000000000000000000..f39245478ba424aae8c1668987161e94593ddca2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02535.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02535") +public class BenchmarkTest02535 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02535"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02536.java b/OWASP DATASET/BenchmarkTest02536.java new file mode 100644 index 0000000000000000000000000000000000000000..2c9e1b66bdb227fd4560ec9b4a48b3e518b9625a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02536.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02536") +public class BenchmarkTest02536 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02536"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + // System.out.println("no results for query: " + sql + " because the Spring batchUpdate + // method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02537.java b/OWASP DATASET/BenchmarkTest02537.java new file mode 100644 index 0000000000000000000000000000000000000000..bd2943ccd2ccd98193fa51994ef95445f0c12554 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02537.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02537") +public class BenchmarkTest02537 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02537"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + // System.out.println("no results for query: " + sql + " because the Spring batchUpdate + // method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02538.java b/OWASP DATASET/BenchmarkTest02538.java new file mode 100644 index 0000000000000000000000000000000000000000..b2cabaaf6c278fd9287853091d145a22a296d6b8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02538.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02538") +public class BenchmarkTest02538 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02538"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String sql = + "SELECT TOP 1 USERNAME from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + Object results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, new Object[] {}, String.class); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(results.toString())); + // System.out.println(results.toString()); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a72634 = param; // assign + StringBuilder b72634 = new StringBuilder(a72634); // stick in stringbuilder + b72634.append(" SafeStuff"); // append some safe content + b72634.replace( + b72634.length() - "Chars".length(), + b72634.length(), + "Chars"); // replace some of the end content + java.util.HashMap map72634 = new java.util.HashMap(); + map72634.put("key72634", b72634.toString()); // put in a collection + String c72634 = (String) map72634.get("key72634"); // get it back out + String d72634 = c72634.substring(0, c72634.length() - 1); // extract most of it + String e72634 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d72634.getBytes()))); // B64 encode and decode it + String f72634 = e72634.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g72634 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g72634); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02539.java b/OWASP DATASET/BenchmarkTest02539.java new file mode 100644 index 0000000000000000000000000000000000000000..e482541d10ff91566f4bc19ff5151029effcc3c7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02539.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02539") +public class BenchmarkTest02539 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02539"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + org.springframework.jdbc.support.rowset.SqlRowSet results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForRowSet(sql); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + while (results.next()) { + response.getWriter() + .println( + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(results.getString("USERNAME")) + + " "); + // System.out.println(results.getString("USERNAME")); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a9290 = param; // assign + StringBuilder b9290 = new StringBuilder(a9290); // stick in stringbuilder + b9290.append(" SafeStuff"); // append some safe content + b9290.replace( + b9290.length() - "Chars".length(), + b9290.length(), + "Chars"); // replace some of the end content + java.util.HashMap map9290 = new java.util.HashMap(); + map9290.put("key9290", b9290.toString()); // put in a collection + String c9290 = (String) map9290.get("key9290"); // get it back out + String d9290 = c9290.substring(0, c9290.length() - 1); // extract most of it + String e9290 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d9290.getBytes()))); // B64 encode and decode it + String f9290 = e9290.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g9290 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g9290); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02540.java b/OWASP DATASET/BenchmarkTest02540.java new file mode 100644 index 0000000000000000000000000000000000000000..b13746351e41de3d64952f12b86c20abac00d8c7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02540.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02540") +public class BenchmarkTest02540 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02540"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02541.java b/OWASP DATASET/BenchmarkTest02541.java new file mode 100644 index 0000000000000000000000000000000000000000..03d91c93d148354fd6ea83a8ea93763bfc9f3146 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02541.java @@ -0,0 +1,78 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02541") +public class BenchmarkTest02541 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02541"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.addBatch(sql); + int[] counts = statement.executeBatch(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(sql, counts, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02542.java b/OWASP DATASET/BenchmarkTest02542.java new file mode 100644 index 0000000000000000000000000000000000000000..2302f093cc0997d9e47a411acd8c9585a60c09bd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02542.java @@ -0,0 +1,74 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02542") +public class BenchmarkTest02542 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02542"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02543.java b/OWASP DATASET/BenchmarkTest02543.java new file mode 100644 index 0000000000000000000000000000000000000000..2adafc876e3743c9287cd6bb4cf8dab89b443470 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02543.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02543") +public class BenchmarkTest02543 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02543"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02544.java b/OWASP DATASET/BenchmarkTest02544.java new file mode 100644 index 0000000000000000000000000000000000000000..e4e89da07969068add08789ccaec9b217a410876 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02544.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02544") +public class BenchmarkTest02544 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02544"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02545.java b/OWASP DATASET/BenchmarkTest02545.java new file mode 100644 index 0000000000000000000000000000000000000000..f471f880b1e1df63237f2add1e59b0e75db36344 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02545.java @@ -0,0 +1,77 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02545") +public class BenchmarkTest02545 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02545"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02546.java b/OWASP DATASET/BenchmarkTest02546.java new file mode 100644 index 0000000000000000000000000000000000000000..3e398043ceb6a78002eb0c813f8733ec425ab0a2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02546.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02546") +public class BenchmarkTest02546 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String[] values = request.getParameterValues("BenchmarkTest02546"); + String param; + if (values != null && values.length > 0) param = values[0]; + else param = ""; + + String bar = doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02547.java b/OWASP DATASET/BenchmarkTest02547.java new file mode 100644 index 0000000000000000000000000000000000000000..5d568009bc80bc2982cef3918c010f8eeaab12b1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02547.java @@ -0,0 +1,181 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02547") +public class BenchmarkTest02547 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02547" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02547" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02547" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02548.java b/OWASP DATASET/BenchmarkTest02548.java new file mode 100644 index 0000000000000000000000000000000000000000..a71f6031e566d999c6f0139bd52a2ab9044ac3cf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02548.java @@ -0,0 +1,186 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02548") +public class BenchmarkTest02548 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02548" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02548" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02548" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02549.java b/OWASP DATASET/BenchmarkTest02549.java new file mode 100644 index 0000000000000000000000000000000000000000..5f6795d7b206d7e4ccf19cc1703ac7e55bff5e36 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02549.java @@ -0,0 +1,185 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02549") +public class BenchmarkTest02549 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02549" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02549" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02549" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding", "SunJCE"); + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz12557 = new StringBuilder(param); + String bar = sbxyz12557.append("_SafeStuff").toString(); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02550.java b/OWASP DATASET/BenchmarkTest02550.java new file mode 100644 index 0000000000000000000000000000000000000000..4f3ba38d1c532a3fea1b1268857bfdc1606c66f1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02550.java @@ -0,0 +1,150 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02550") +public class BenchmarkTest02550 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02550" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02550" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02550" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02551.java b/OWASP DATASET/BenchmarkTest02551.java new file mode 100644 index 0000000000000000000000000000000000000000..6ad19e67a903201e3846a2793d26759c6f863d18 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02551.java @@ -0,0 +1,146 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02551") +public class BenchmarkTest02551 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02551" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02551" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02551" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "AES/CCM/NoPadding", java.security.Security.getProvider("BC")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz98255 = new StringBuilder(param); + bar = sbxyz98255.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02552.java b/OWASP DATASET/BenchmarkTest02552.java new file mode 100644 index 0000000000000000000000000000000000000000..bb6f1af3cfe9d61b84ef15c7e7676048b20fbaaa --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02552.java @@ -0,0 +1,156 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-02/BenchmarkTest02552") +public class BenchmarkTest02552 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02552" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02552" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02552" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + // java.security.SecureRandom random = new java.security.SecureRandom(); + // byte[] iv = random.generateSeed(16); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg2", "AES/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02553.java b/OWASP DATASET/BenchmarkTest02553.java new file mode 100644 index 0000000000000000000000000000000000000000..b94b3ab19e9970ee127cdabd33666bf4d699597a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02553.java @@ -0,0 +1,136 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest02553") +public class BenchmarkTest02553 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02553" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02553" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02553" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + javax.naming.directory.DirContext ctx = ads.getDirContext(); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + bar + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + // System.out.println("Filter " + filter); + boolean found = false; + javax.naming.NamingEnumeration results = + ctx.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map11026 = new java.util.HashMap(); + map11026.put("keyA-11026", "a_Value"); // put some stuff in the collection + map11026.put("keyB-11026", param); // put it in a collection + map11026.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map11026.get("keyB-11026"); // get it back out + bar = (String) map11026.get("keyA-11026"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02554.java b/OWASP DATASET/BenchmarkTest02554.java new file mode 100644 index 0000000000000000000000000000000000000000..159fd37e2d55ccf362c96efc2c3d1fa48416e34d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02554.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-03/BenchmarkTest02554") +public class BenchmarkTest02554 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02554" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02554" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02554" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02555.java b/OWASP DATASET/BenchmarkTest02555.java new file mode 100644 index 0000000000000000000000000000000000000000..5040e6f2bb258a55acd746be1799ab0185175c84 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02555.java @@ -0,0 +1,103 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-03/BenchmarkTest02555") +public class BenchmarkTest02555 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02555" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02555" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02555" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + java.io.File fileTarget = new java.io.File(bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02556.java b/OWASP DATASET/BenchmarkTest02556.java new file mode 100644 index 0000000000000000000000000000000000000000..a9966eef2d0a8b981ac159644c75bb11832dc304 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02556.java @@ -0,0 +1,101 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-03/BenchmarkTest02556") +public class BenchmarkTest02556 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02556" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02556" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02556" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + java.io.File fileTarget = new java.io.File(bar); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02557.java b/OWASP DATASET/BenchmarkTest02557.java new file mode 100644 index 0000000000000000000000000000000000000000..3a4f5190348bc73a8b6678badd0b8ad12e4708b0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02557.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-03/BenchmarkTest02557") +public class BenchmarkTest02557 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02557" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02557" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02557" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + java.io.File fileTarget = new java.io.File(bar, "/Test.txt"); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02558.java b/OWASP DATASET/BenchmarkTest02558.java new file mode 100644 index 0000000000000000000000000000000000000000..63a38c51eaae1cdf25f91cca418dd9a33a8f3432 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02558.java @@ -0,0 +1,101 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-03/BenchmarkTest02558") +public class BenchmarkTest02558 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02558" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02558" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02558" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + java.io.File fileTarget = new java.io.File(bar, "/Test.txt"); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02559.java b/OWASP DATASET/BenchmarkTest02559.java new file mode 100644 index 0000000000000000000000000000000000000000..1d439d969daeb2e1443c83737e526b41cddddbd2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02559.java @@ -0,0 +1,118 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-03/BenchmarkTest02559") +public class BenchmarkTest02559 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02559" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02559" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02559" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // FILE URIs are tricky because they are different between Mac and Windows because of lack + // of standardization. + // Mac requires an extra slash for some reason. + String startURIslashes = ""; + if (System.getProperty("os.name").indexOf("Windows") != -1) + if (System.getProperty("os.name").indexOf("Windows") != -1) startURIslashes = "/"; + else startURIslashes = "//"; + + try { + java.net.URI fileURI = + new java.net.URI( + "file:" + + startURIslashes + + org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + .replace('\\', '/') + .replace(' ', '_') + + bar); + java.io.File fileTarget = new java.io.File(fileURI); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } catch (java.net.URISyntaxException e) { + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02560.java b/OWASP DATASET/BenchmarkTest02560.java new file mode 100644 index 0000000000000000000000000000000000000000..c996d248dd4338489847a63c75bf2fb7c9158e9e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02560.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-03/BenchmarkTest02560") +public class BenchmarkTest02560 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02560" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02560" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02560" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(new java.io.File(fileName)); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting FileInputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02561.java b/OWASP DATASET/BenchmarkTest02561.java new file mode 100644 index 0000000000000000000000000000000000000000..6e8aa81f74e9e2a3defeed329f23d5a0f977d824 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02561.java @@ -0,0 +1,119 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-03/BenchmarkTest02561") +public class BenchmarkTest02561 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02561" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02561" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02561" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(fileName); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02562.java b/OWASP DATASET/BenchmarkTest02562.java new file mode 100644 index 0000000000000000000000000000000000000000..cf88d163c41aa8da0f93464bf6f0fd7a7e292589 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02562.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-03/BenchmarkTest02562") +public class BenchmarkTest02562 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02562" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02562" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02562" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(fileName); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02563.java b/OWASP DATASET/BenchmarkTest02563.java new file mode 100644 index 0000000000000000000000000000000000000000..f5840b2c9766c1e9d4e50a9a16658571bf2e4319 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02563.java @@ -0,0 +1,127 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-03/BenchmarkTest02563") +public class BenchmarkTest02563 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02563" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02563" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02563" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName), false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a99746 = param; // assign + StringBuilder b99746 = new StringBuilder(a99746); // stick in stringbuilder + b99746.append(" SafeStuff"); // append some safe content + b99746.replace( + b99746.length() - "Chars".length(), + b99746.length(), + "Chars"); // replace some of the end content + java.util.HashMap map99746 = new java.util.HashMap(); + map99746.put("key99746", b99746.toString()); // put in a collection + String c99746 = (String) map99746.get("key99746"); // get it back out + String d99746 = c99746.substring(0, c99746.length() - 1); // extract most of it + String e99746 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d99746.getBytes()))); // B64 encode and decode it + String f99746 = e99746.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g99746 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g99746); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02564.java b/OWASP DATASET/BenchmarkTest02564.java new file mode 100644 index 0000000000000000000000000000000000000000..f670c9d3645594e4f24471761f2079615f73ba10 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02564.java @@ -0,0 +1,125 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-03/BenchmarkTest02564") +public class BenchmarkTest02564 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02564" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02564" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02564" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(new java.io.File(fileName), false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02565.java b/OWASP DATASET/BenchmarkTest02565.java new file mode 100644 index 0000000000000000000000000000000000000000..0dcf90dc4d32d4e19d49724e478e128a7c0db04a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02565.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-03/BenchmarkTest02565") +public class BenchmarkTest02565 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02565" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02565" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02565" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + try ( + // Create the file first so the test won't throw an exception if it doesn't exist. + // Note: Don't actually do this because this method signature could cause a tool to find + // THIS file constructor + // as a vuln, rather than the File signature we are trying to actually test. + // If necessary, just run the benchmark twice. The 1st run should create all the necessary + // files. + // new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar).createNewFile(); + + java.io.FileOutputStream fos = + new java.io.FileOutputStream(new java.io.FileInputStream(fileName).getFD()); ) { + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02566.java b/OWASP DATASET/BenchmarkTest02566.java new file mode 100644 index 0000000000000000000000000000000000000000..24b79ee3cdd66ee5c3164fee5e76d2c0628180f2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02566.java @@ -0,0 +1,121 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-03/BenchmarkTest02566") +public class BenchmarkTest02566 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02566" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02566" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02566" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + try ( + // Create the file first so the test won't throw an exception if it doesn't exist. + // Note: Don't actually do this because this method signature could cause a tool to find + // THIS file constructor + // as a vuln, rather than the File signature we are trying to actually test. + // If necessary, just run the benchmark twice. The 1st run should create all the necessary + // files. + // new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar).createNewFile(); + + java.io.FileOutputStream fos = + new java.io.FileOutputStream(new java.io.FileInputStream(fileName).getFD()); ) { + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02567.java b/OWASP DATASET/BenchmarkTest02567.java new file mode 100644 index 0000000000000000000000000000000000000000..33dc7378865c30e66007d83159f307266ee0a877 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02567.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-03/BenchmarkTest02567") +public class BenchmarkTest02567 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02567" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02567" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02567" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName, false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02568.java b/OWASP DATASET/BenchmarkTest02568.java new file mode 100644 index 0000000000000000000000000000000000000000..cbf96177a0bd4306757e6e10782ad01059d65696 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02568.java @@ -0,0 +1,125 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-03/BenchmarkTest02568") +public class BenchmarkTest02568 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02568" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02568" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02568" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02569.java b/OWASP DATASET/BenchmarkTest02569.java new file mode 100644 index 0000000000000000000000000000000000000000..d871824211b7fe704cacd85f70c77fb1c8cbde03 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02569.java @@ -0,0 +1,125 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-03/BenchmarkTest02569") +public class BenchmarkTest02569 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02569" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02569" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02569" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02570.java b/OWASP DATASET/BenchmarkTest02570.java new file mode 100644 index 0000000000000000000000000000000000000000..2c0198a331ef808f8604c3ee139d9ee4042cda85 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02570.java @@ -0,0 +1,127 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-03/BenchmarkTest02570") +public class BenchmarkTest02570 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02570" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02570" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02570" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + java.io.InputStream is = null; + + try { + java.nio.file.Path path = java.nio.file.Paths.get(fileName); + is = java.nio.file.Files.newInputStream(path, java.nio.file.StandardOpenOption.READ); + byte[] b = new byte[1000]; + int size = is.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + is.close(); + } catch (Exception e) { + System.out.println("Couldn't open InputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting InputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (is != null) { + try { + is.close(); + is = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02571.java b/OWASP DATASET/BenchmarkTest02571.java new file mode 100644 index 0000000000000000000000000000000000000000..c8e58a166182dad5e187bc9c1636747e69dd1336 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02571.java @@ -0,0 +1,151 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest02571") +public class BenchmarkTest02571 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02571" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02571" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02571" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person))(|(uid=" + bar + ")(street={0}))"; + Object[] filters = new Object[] {"The streetz 4 Ms bar"}; + + javax.naming.directory.DirContext ctx = ads.getDirContext(); + javax.naming.directory.InitialDirContext idc = + (javax.naming.directory.InitialDirContext) ctx; + boolean found = false; + javax.naming.NamingEnumeration results = + idc.search(base, filter, filters, sc); + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02572.java b/OWASP DATASET/BenchmarkTest02572.java new file mode 100644 index 0000000000000000000000000000000000000000..5dd09df1ecd03dcc5b6fbaf2cc02f9480199936f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02572.java @@ -0,0 +1,142 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/ldapi-00/BenchmarkTest02572") +public class BenchmarkTest02572 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02572" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02572" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02572" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + org.owasp.benchmark.helpers.LDAPManager ads = new org.owasp.benchmark.helpers.LDAPManager(); + try { + response.setContentType("text/html;charset=UTF-8"); + String base = "ou=users,ou=system"; + javax.naming.directory.SearchControls sc = new javax.naming.directory.SearchControls(); + sc.setSearchScope(javax.naming.directory.SearchControls.SUBTREE_SCOPE); + String filter = "(&(objectclass=person)(uid=" + bar + "))"; + + javax.naming.directory.DirContext ctx = ads.getDirContext(); + javax.naming.directory.InitialDirContext idc = + (javax.naming.directory.InitialDirContext) ctx; + boolean found = false; + javax.naming.NamingEnumeration results = + idc.search(base, filter, sc); + + while (results.hasMore()) { + javax.naming.directory.SearchResult sr = + (javax.naming.directory.SearchResult) results.next(); + javax.naming.directory.Attributes attrs = sr.getAttributes(); + + javax.naming.directory.Attribute attr = attrs.get("uid"); + javax.naming.directory.Attribute attr2 = attrs.get("street"); + if (attr != null) { + response.getWriter() + .println( + "LDAP query results:
" + + "Record found with name " + + attr.get() + + "
" + + "Address: " + + attr2.get() + + "
"); + // System.out.println("record found " + attr.get()); + found = true; + } + } + if (!found) { + response.getWriter() + .println( + "LDAP query results: nothing found for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(filter)); + } + } catch (javax.naming.NamingException e) { + throw new ServletException(e); + } finally { + try { + ads.closeDirContext(); + } catch (Exception e) { + throw new ServletException(e); + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02573.java b/OWASP DATASET/BenchmarkTest02573.java new file mode 100644 index 0000000000000000000000000000000000000000..4b47a1a36ba610c6bc1d5ef0eba8919f5c3edc93 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02573.java @@ -0,0 +1,144 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02573") +public class BenchmarkTest02573 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02573" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02573" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02573" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02574.java b/OWASP DATASET/BenchmarkTest02574.java new file mode 100644 index 0000000000000000000000000000000000000000..95e612cc995331a5699aaabaff40e4d44a1213d2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02574.java @@ -0,0 +1,137 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02574") +public class BenchmarkTest02574 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02574" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02574" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02574" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.lang.String)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02575.java b/OWASP DATASET/BenchmarkTest02575.java new file mode 100644 index 0000000000000000000000000000000000000000..551e46e638f8df9b366811c1ef9954f04225d1d2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02575.java @@ -0,0 +1,134 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02575") +public class BenchmarkTest02575 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02575" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02575" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02575" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02576.java b/OWASP DATASET/BenchmarkTest02576.java new file mode 100644 index 0000000000000000000000000000000000000000..4dab252c4af4d086b3c2488247eca2b3b3189bf0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02576.java @@ -0,0 +1,134 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02576") +public class BenchmarkTest02576 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02576" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02576" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02576" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-256"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02577.java b/OWASP DATASET/BenchmarkTest02577.java new file mode 100644 index 0000000000000000000000000000000000000000..2cfe263e5c85b37d428a2450b6f64ec606748017 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02577.java @@ -0,0 +1,143 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02577") +public class BenchmarkTest02577 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02577" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02577" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02577" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02578.java b/OWASP DATASET/BenchmarkTest02578.java new file mode 100644 index 0000000000000000000000000000000000000000..ee32846b0229127e0c5ee2d2cf0a7f82c2d8cdf9 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02578.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02578") +public class BenchmarkTest02578 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02578" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02578" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02578" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(java.util.Locale.US, bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02579.java b/OWASP DATASET/BenchmarkTest02579.java new file mode 100644 index 0000000000000000000000000000000000000000..fb09d7ca44571a04ca2df69c8d98ac6855070b2b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02579.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02579") +public class BenchmarkTest02579 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02579" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02579" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02579" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02580.java b/OWASP DATASET/BenchmarkTest02580.java new file mode 100644 index 0000000000000000000000000000000000000000..479f09cb9cb12dba471663b224b4d16b635af72a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02580.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02580") +public class BenchmarkTest02580 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02580" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02580" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02580" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz1658 = new StringBuilder(param); + String bar = sbxyz1658.append("_SafeStuff").toString(); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02581.java b/OWASP DATASET/BenchmarkTest02581.java new file mode 100644 index 0000000000000000000000000000000000000000..d171006187c418aa57dea4165111c330a34322b5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02581.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02581") +public class BenchmarkTest02581 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02581" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02581" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02581" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02582.java b/OWASP DATASET/BenchmarkTest02582.java new file mode 100644 index 0000000000000000000000000000000000000000..38a55a955ff087f17c0f0c21a719ba6fd17a61e3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02582.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02582") +public class BenchmarkTest02582 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02582" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02582" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02582" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar.toCharArray()); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz18070 = new StringBuilder(param); + String bar = sbxyz18070.append("_SafeStuff").toString(); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02583.java b/OWASP DATASET/BenchmarkTest02583.java new file mode 100644 index 0000000000000000000000000000000000000000..572b1a1cb7a4f166279fd486a67f58c688d01376 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02583.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02583") +public class BenchmarkTest02583 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02583" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02583" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02583" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02584.java b/OWASP DATASET/BenchmarkTest02584.java new file mode 100644 index 0000000000000000000000000000000000000000..a2dfc9512c9fa9023af25f0dbdbc142ba6291b2c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02584.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02584") +public class BenchmarkTest02584 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02584" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02584" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02584" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz36210 = new StringBuilder(param); + String bar = sbxyz36210.append("_SafeStuff").toString(); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02585.java b/OWASP DATASET/BenchmarkTest02585.java new file mode 100644 index 0000000000000000000000000000000000000000..c968c96c80f8aa93734d16c2116be7b71a34a6c5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02585.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02585") +public class BenchmarkTest02585 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02585" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02585" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02585" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02586.java b/OWASP DATASET/BenchmarkTest02586.java new file mode 100644 index 0000000000000000000000000000000000000000..cb53cfe7352a948604ef05c7b52a75d5b754506a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02586.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02586") +public class BenchmarkTest02586 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02586" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02586" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02586" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02587.java b/OWASP DATASET/BenchmarkTest02587.java new file mode 100644 index 0000000000000000000000000000000000000000..b9f3bad87cae6ae9babc5d07a0cc90c33ba9462c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02587.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02587") +public class BenchmarkTest02587 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02587" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02587" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02587" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a93081 = param; // assign + StringBuilder b93081 = new StringBuilder(a93081); // stick in stringbuilder + b93081.append(" SafeStuff"); // append some safe content + b93081.replace( + b93081.length() - "Chars".length(), + b93081.length(), + "Chars"); // replace some of the end content + java.util.HashMap map93081 = new java.util.HashMap(); + map93081.put("key93081", b93081.toString()); // put in a collection + String c93081 = (String) map93081.get("key93081"); // get it back out + String d93081 = c93081.substring(0, c93081.length() - 1); // extract most of it + String e93081 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d93081.getBytes()))); // B64 encode and decode it + String f93081 = e93081.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f93081); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02588.java b/OWASP DATASET/BenchmarkTest02588.java new file mode 100644 index 0000000000000000000000000000000000000000..1000a79780b2317c0de27a145edc6783c5040341 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02588.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02588") +public class BenchmarkTest02588 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02588" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02588" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02588" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(java.util.Locale.US, bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a1227 = param; // assign + StringBuilder b1227 = new StringBuilder(a1227); // stick in stringbuilder + b1227.append(" SafeStuff"); // append some safe content + b1227.replace( + b1227.length() - "Chars".length(), + b1227.length(), + "Chars"); // replace some of the end content + java.util.HashMap map1227 = new java.util.HashMap(); + map1227.put("key1227", b1227.toString()); // put in a collection + String c1227 = (String) map1227.get("key1227"); // get it back out + String d1227 = c1227.substring(0, c1227.length() - 1); // extract most of it + String e1227 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d1227.getBytes()))); // B64 encode and decode it + String f1227 = e1227.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f1227); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02589.java b/OWASP DATASET/BenchmarkTest02589.java new file mode 100644 index 0000000000000000000000000000000000000000..fa117cd30a7f5c059663057d59f2446c4119d7a8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02589.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02589") +public class BenchmarkTest02589 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02589" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02589" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02589" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(java.util.Locale.US, bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02590.java b/OWASP DATASET/BenchmarkTest02590.java new file mode 100644 index 0000000000000000000000000000000000000000..472d1ac0a26f18380b0523432fd4930c4433ce9c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02590.java @@ -0,0 +1,90 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02590") +public class BenchmarkTest02590 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02590" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02590" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02590" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(java.util.Locale.US, bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map35520 = new java.util.HashMap(); + map35520.put("keyA-35520", "a_Value"); // put some stuff in the collection + map35520.put("keyB-35520", param); // put it in a collection + map35520.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map35520.get("keyB-35520"); // get it back out + bar = (String) map35520.get("keyA-35520"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02591.java b/OWASP DATASET/BenchmarkTest02591.java new file mode 100644 index 0000000000000000000000000000000000000000..a64020402660e97d58ab42099d77464590dfb13d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02591.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02591") +public class BenchmarkTest02591 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02591" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02591" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02591" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {bar, "b"}; + response.getWriter().printf("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz9811 = new StringBuilder(param); + String bar = sbxyz9811.append("_SafeStuff").toString(); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02592.java b/OWASP DATASET/BenchmarkTest02592.java new file mode 100644 index 0000000000000000000000000000000000000000..886ab6d6cd7f262913ddec3223c0ed576ec28391 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02592.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02592") +public class BenchmarkTest02592 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02592" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02592" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02592" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {bar, "b"}; + response.getWriter().printf("Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz52014 = new StringBuilder(param); + bar = sbxyz52014.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02593.java b/OWASP DATASET/BenchmarkTest02593.java new file mode 100644 index 0000000000000000000000000000000000000000..13f2a514ec4b268d54616f8bda437d55a638f385 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02593.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02593") +public class BenchmarkTest02593 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02593" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02593" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02593" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02594.java b/OWASP DATASET/BenchmarkTest02594.java new file mode 100644 index 0000000000000000000000000000000000000000..004f8147d96da69798845724a6dcb511644557a3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02594.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02594") +public class BenchmarkTest02594 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02594" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02594" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02594" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar.toCharArray()); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02595.java b/OWASP DATASET/BenchmarkTest02595.java new file mode 100644 index 0000000000000000000000000000000000000000..d73a5e861ff4b0429549f88c7909e7f84bc02673 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02595.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02595") +public class BenchmarkTest02595 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02595" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02595" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02595" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar.toCharArray()); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02596.java b/OWASP DATASET/BenchmarkTest02596.java new file mode 100644 index 0000000000000000000000000000000000000000..9af55845ce0c8442667ce4f8c9c33bc35b4bffb3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02596.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02596") +public class BenchmarkTest02596 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02596" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02596" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02596" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02597.java b/OWASP DATASET/BenchmarkTest02597.java new file mode 100644 index 0000000000000000000000000000000000000000..cd0b2c811c80be18d5d584ce506d4ed6e1d6d2b6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02597.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02597") +public class BenchmarkTest02597 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02597" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02597" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02597" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz19350 = new StringBuilder(param); + bar = sbxyz19350.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02598.java b/OWASP DATASET/BenchmarkTest02598.java new file mode 100644 index 0000000000000000000000000000000000000000..ae37642d0fe27c1e5c4a40c7d9e7dd0387b7407d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02598.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02598") +public class BenchmarkTest02598 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02598" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02598" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02598" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02599.java b/OWASP DATASET/BenchmarkTest02599.java new file mode 100644 index 0000000000000000000000000000000000000000..1026da9e882db8c6d62467e51275a70125ac60e8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02599.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02599") +public class BenchmarkTest02599 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02599" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02599" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02599" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar.toCharArray()); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02600.java b/OWASP DATASET/BenchmarkTest02600.java new file mode 100644 index 0000000000000000000000000000000000000000..d2f23d531df128f92f1526eb3bf194528b500d54 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02600.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02600") +public class BenchmarkTest02600 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02600" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02600" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02600" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar.toCharArray(), 0, length); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02601.java b/OWASP DATASET/BenchmarkTest02601.java new file mode 100644 index 0000000000000000000000000000000000000000..b5cd901e477e001ffd506f279a36c0b81dae7738 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02601.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02601") +public class BenchmarkTest02601 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02601" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02601" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02601" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + int length = 1; + if (bar != null) { + length = bar.length(); + response.getWriter().write(bar.toCharArray(), 0, length); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02602.java b/OWASP DATASET/BenchmarkTest02602.java new file mode 100644 index 0000000000000000000000000000000000000000..19b289be499aa1e9443526551db070ae2f7c6e60 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02602.java @@ -0,0 +1,150 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02602") +public class BenchmarkTest02602 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02602" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02602" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02602" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + byte[] bytes = new byte[10]; + new java.util.Random().nextBytes(bytes); + String rememberMeKey = org.owasp.esapi.ESAPI.encoder().encodeForBase64(bytes, true); + + String user = "Byron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextBytes() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a3617 = param; // assign + StringBuilder b3617 = new StringBuilder(a3617); // stick in stringbuilder + b3617.append(" SafeStuff"); // append some safe content + b3617.replace( + b3617.length() - "Chars".length(), + b3617.length(), + "Chars"); // replace some of the end content + java.util.HashMap map3617 = new java.util.HashMap(); + map3617.put("key3617", b3617.toString()); // put in a collection + String c3617 = (String) map3617.get("key3617"); // get it back out + String d3617 = c3617.substring(0, c3617.length() - 1); // extract most of it + String e3617 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d3617.getBytes()))); // B64 encode and decode it + String f3617 = e3617.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f3617); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02603.java b/OWASP DATASET/BenchmarkTest02603.java new file mode 100644 index 0000000000000000000000000000000000000000..abebfd0638d9407788e818fdd5bbcc44dbd94785 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02603.java @@ -0,0 +1,133 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02603") +public class BenchmarkTest02603 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02603" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02603" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02603" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + byte[] bytes = new byte[10]; + new java.util.Random().nextBytes(bytes); + String rememberMeKey = org.owasp.esapi.ESAPI.encoder().encodeForBase64(bytes, true); + + String user = "Byron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextBytes() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02604.java b/OWASP DATASET/BenchmarkTest02604.java new file mode 100644 index 0000000000000000000000000000000000000000..2a3a5d76530e7ff6cb00502dc415839361bf6039 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02604.java @@ -0,0 +1,149 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02604") +public class BenchmarkTest02604 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02604" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02604" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02604" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + double value = new java.util.Random().nextDouble(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Donna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a92079 = param; // assign + StringBuilder b92079 = new StringBuilder(a92079); // stick in stringbuilder + b92079.append(" SafeStuff"); // append some safe content + b92079.replace( + b92079.length() - "Chars".length(), + b92079.length(), + "Chars"); // replace some of the end content + java.util.HashMap map92079 = new java.util.HashMap(); + map92079.put("key92079", b92079.toString()); // put in a collection + String c92079 = (String) map92079.get("key92079"); // get it back out + String d92079 = c92079.substring(0, c92079.length() - 1); // extract most of it + String e92079 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d92079.getBytes()))); // B64 encode and decode it + String f92079 = e92079.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f92079); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02605.java b/OWASP DATASET/BenchmarkTest02605.java new file mode 100644 index 0000000000000000000000000000000000000000..b9b710f45b987188c0a30cd638c14dc80207a164 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02605.java @@ -0,0 +1,134 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02605") +public class BenchmarkTest02605 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02605" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02605" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02605" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + double value = new java.util.Random().nextDouble(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Donna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02606.java b/OWASP DATASET/BenchmarkTest02606.java new file mode 100644 index 0000000000000000000000000000000000000000..2f5b2c76bf51bc6ccdf4c303d9ee4ea962c19080 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02606.java @@ -0,0 +1,139 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02606") +public class BenchmarkTest02606 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02606" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02606" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02606" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + float rand = new java.util.Random().nextFloat(); + String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "Floyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02607.java b/OWASP DATASET/BenchmarkTest02607.java new file mode 100644 index 0000000000000000000000000000000000000000..1e6dd16122b8c1e574cf6bf4215170afddf600cf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02607.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest02607") +public class BenchmarkTest02607 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02607" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02607" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02607" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz75490 = new StringBuilder(param); + String bar = sbxyz75490.append("_SafeStuff").toString(); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02608.java b/OWASP DATASET/BenchmarkTest02608.java new file mode 100644 index 0000000000000000000000000000000000000000..3da7c0990e8bbbb680d7b8aaa4df50bf8b81c125 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02608.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02608") +public class BenchmarkTest02608 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02608" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02608" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02608" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write("Parameter value: " + bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02609.java b/OWASP DATASET/BenchmarkTest02609.java new file mode 100644 index 0000000000000000000000000000000000000000..cc2501d44d9b0507c2fa279b410d56ffd39eafc3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02609.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02609") +public class BenchmarkTest02609 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02609" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02609" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02609" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write("Parameter value: " + bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02610.java b/OWASP DATASET/BenchmarkTest02610.java new file mode 100644 index 0000000000000000000000000000000000000000..3f8464cf60213a79813ed9006f09186ac719a386 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02610.java @@ -0,0 +1,122 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-03/BenchmarkTest02610") +public class BenchmarkTest02610 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02610" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02610" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02610" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02611.java b/OWASP DATASET/BenchmarkTest02611.java new file mode 100644 index 0000000000000000000000000000000000000000..2893bd5c3c5e3b51b65edb50fff14fa287c196b6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02611.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-03/BenchmarkTest02611") +public class BenchmarkTest02611 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02611" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02611" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02611" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String cmd = ""; + String a1 = ""; + String a2 = ""; + String[] args = null; + String osName = System.getProperty("os.name"); + + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + cmd = "echo "; + args = new String[] {a1, a2, cmd, bar}; + } else { + a1 = "sh"; + a2 = "-c"; + cmd = org.owasp.benchmark.helpers.Utils.getOSCommandString("ls "); + args = new String[] {a1, a2, cmd + bar}; + } + + String[] argsEnv = {"foo=bar"}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02612.java b/OWASP DATASET/BenchmarkTest02612.java new file mode 100644 index 0000000000000000000000000000000000000000..51ce32fa5338fc72554ecaf093d6594360572a5f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02612.java @@ -0,0 +1,100 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-03/BenchmarkTest02612") +public class BenchmarkTest02612 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02612" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02612" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02612" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02613.java b/OWASP DATASET/BenchmarkTest02613.java new file mode 100644 index 0000000000000000000000000000000000000000..7f1225efb656a77144db665f8b461e2594b17ad0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02613.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-03/BenchmarkTest02613") +public class BenchmarkTest02613 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02613" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02613" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02613" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + try { + Process p = r.exec(cmd, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02614.java b/OWASP DATASET/BenchmarkTest02614.java new file mode 100644 index 0000000000000000000000000000000000000000..f5161a75de13a0cd5f9ac86adbddb93b31c73c53 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02614.java @@ -0,0 +1,147 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02614") +public class BenchmarkTest02614 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02614" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02614" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02614" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + getNextNumber(numGen, randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeBystander"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + void getNextNumber(java.util.Random generator, byte[] barray) { + generator.nextBytes(barray); + } + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02615.java b/OWASP DATASET/BenchmarkTest02615.java new file mode 100644 index 0000000000000000000000000000000000000000..ac82d105a8c4266c48e4e44894929dde30dd7e70 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02615.java @@ -0,0 +1,137 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02615") +public class BenchmarkTest02615 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02615" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02615" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02615" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02616.java b/OWASP DATASET/BenchmarkTest02616.java new file mode 100644 index 0000000000000000000000000000000000000000..1a16bfd33e5516d41cc8c73472cdacfeb66b1c80 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02616.java @@ -0,0 +1,149 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02616") +public class BenchmarkTest02616 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02616" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02616" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02616" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + java.util.Random numGen = java.security.SecureRandom.getInstance("SHA1PRNG"); + double rand = getNextNumber(numGen); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonatella"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + double getNextNumber(java.util.Random generator) { + return generator.nextDouble(); + } + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02617.java b/OWASP DATASET/BenchmarkTest02617.java new file mode 100644 index 0000000000000000000000000000000000000000..a8aa485032081c0ae0a5d13c360ddc16a45f48da --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02617.java @@ -0,0 +1,163 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02617") +public class BenchmarkTest02617 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02617" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02617" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02617" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + java.security.SecureRandom secureRandomGenerator = + java.security.SecureRandom.getInstance("SHA1PRNG"); + + // Get 40 random bytes + byte[] randomBytes = new byte[40]; + secureRandomGenerator.nextBytes(randomBytes); + + String rememberMeKey = + org.owasp.esapi.ESAPI.encoder().encodeForBase64(randomBytes, true); + + String user = "SafeByron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextBytes() - TestCase"); + throw new ServletException(e); + } finally { + response.getWriter() + .println( + "Randomness Test java.security.SecureRandom.nextBytes(byte[]) executed"); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a80801 = param; // assign + StringBuilder b80801 = new StringBuilder(a80801); // stick in stringbuilder + b80801.append(" SafeStuff"); // append some safe content + b80801.replace( + b80801.length() - "Chars".length(), + b80801.length(), + "Chars"); // replace some of the end content + java.util.HashMap map80801 = new java.util.HashMap(); + map80801.put("key80801", b80801.toString()); // put in a collection + String c80801 = (String) map80801.get("key80801"); // get it back out + String d80801 = c80801.substring(0, c80801.length() - 1); // extract most of it + String e80801 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d80801.getBytes()))); // B64 encode and decode it + String f80801 = e80801.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f80801); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02618.java b/OWASP DATASET/BenchmarkTest02618.java new file mode 100644 index 0000000000000000000000000000000000000000..1c991613107662be10a6ce21cce9b89f02f2d68c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02618.java @@ -0,0 +1,142 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02618") +public class BenchmarkTest02618 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02618" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02618" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02618" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02619.java b/OWASP DATASET/BenchmarkTest02619.java new file mode 100644 index 0000000000000000000000000000000000000000..02ae7e4e10fff0eef73f778c5d0c3803457d6170 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02619.java @@ -0,0 +1,154 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02619") +public class BenchmarkTest02619 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02619" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02619" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02619" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + float rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextFloat(); + String rememberMeKey = + Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeFloyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextFloat() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextFloat() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02620.java b/OWASP DATASET/BenchmarkTest02620.java new file mode 100644 index 0000000000000000000000000000000000000000..f7f8b911daaf72c0c4f5f937ab7c8892576853c1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02620.java @@ -0,0 +1,138 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02620") +public class BenchmarkTest02620 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02620" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02620" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02620" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + int randNumber = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(99); + String rememberMeKey = Integer.toString(randNumber); + + String user = "SafeInga"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt(int) - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt(int) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz33222 = new StringBuilder(param); + bar = sbxyz33222.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02621.java b/OWASP DATASET/BenchmarkTest02621.java new file mode 100644 index 0000000000000000000000000000000000000000..ec930dae98e09c4b78abaf2fff8b80f9fceff549 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02621.java @@ -0,0 +1,138 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02621") +public class BenchmarkTest02621 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02621" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02621" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02621" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + int r = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "SafeIngrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz33448 = new StringBuilder(param); + bar = sbxyz33448.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02622.java b/OWASP DATASET/BenchmarkTest02622.java new file mode 100644 index 0000000000000000000000000000000000000000..b31fb2020128e1cb0c48029431c2c3f22e77a3b5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02622.java @@ -0,0 +1,90 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest02622") +public class BenchmarkTest02622 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02622" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02622" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02622" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String^,java.lang.Object) + request.getSession().setAttribute(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: '10340' saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz66849 = new StringBuilder(param); + String bar = sbxyz66849.append("_SafeStuff").toString(); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02623.java b/OWASP DATASET/BenchmarkTest02623.java new file mode 100644 index 0000000000000000000000000000000000000000..c442ca1f1da1fdb080972e8043f159d5ac9cd713 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02623.java @@ -0,0 +1,89 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest02623") +public class BenchmarkTest02623 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02623" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02623" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02623" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02624.java b/OWASP DATASET/BenchmarkTest02624.java new file mode 100644 index 0000000000000000000000000000000000000000..4cbe1638ca92b81652550623fc95a8e9b12aca8d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02624.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest02624") +public class BenchmarkTest02624 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02624" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02624" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02624" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map3141 = new java.util.HashMap(); + map3141.put("keyA-3141", "a-Value"); // put some stuff in the collection + map3141.put("keyB-3141", param); // put it in a collection + map3141.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map3141.get("keyB-3141"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02625.java b/OWASP DATASET/BenchmarkTest02625.java new file mode 100644 index 0000000000000000000000000000000000000000..6759a98c584a72cb1ca88949412deaa0e07f1e7d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02625.java @@ -0,0 +1,101 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02625") +public class BenchmarkTest02625 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02625" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02625" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02625" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = connection.prepareCall(sql); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map82391 = new java.util.HashMap(); + map82391.put("keyA-82391", "a-Value"); // put some stuff in the collection + map82391.put("keyB-82391", param); // put it in a collection + map82391.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map82391.get("keyB-82391"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02626.java b/OWASP DATASET/BenchmarkTest02626.java new file mode 100644 index 0000000000000000000000000000000000000000..dd8ebc58a88476c8e8b3b3df550633a3040887ec --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02626.java @@ -0,0 +1,101 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02626") +public class BenchmarkTest02626 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02626" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02626" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02626" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = connection.prepareCall(sql); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02627.java b/OWASP DATASET/BenchmarkTest02627.java new file mode 100644 index 0000000000000000000000000000000000000000..d44339d98c6a5b9afa305933f21dc7792556e1cf --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02627.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02627") +public class BenchmarkTest02627 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02627" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02627" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02627" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02628.java b/OWASP DATASET/BenchmarkTest02628.java new file mode 100644 index 0000000000000000000000000000000000000000..9985904be4f8be4301048b23ac5dc0843d24ee9d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02628.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02628") +public class BenchmarkTest02628 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02628" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02628" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02628" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map23653 = new java.util.HashMap(); + map23653.put("keyA-23653", "a-Value"); // put some stuff in the collection + map23653.put("keyB-23653", param); // put it in a collection + map23653.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map23653.get("keyB-23653"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02629.java b/OWASP DATASET/BenchmarkTest02629.java new file mode 100644 index 0000000000000000000000000000000000000000..027f7d1b8bc7416d8284de8c8f62a23d7298a383 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02629.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02629") +public class BenchmarkTest02629 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02629" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02629" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02629" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02630.java b/OWASP DATASET/BenchmarkTest02630.java new file mode 100644 index 0000000000000000000000000000000000000000..523f2e67543b432caaf1745f3d32bffc13d89be7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02630.java @@ -0,0 +1,100 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02630") +public class BenchmarkTest02630 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02630" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02630" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02630" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "{call " + bar + "}"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.CallableStatement statement = + connection.prepareCall( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + java.sql.ResultSet rs = statement.executeQuery(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02631.java b/OWASP DATASET/BenchmarkTest02631.java new file mode 100644 index 0000000000000000000000000000000000000000..722b51f0a1f1272453463a1115a6f02fc9ce0034 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02631.java @@ -0,0 +1,101 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02631") +public class BenchmarkTest02631 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02631" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02631" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02631" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = connection.prepareStatement(sql); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02632.java b/OWASP DATASET/BenchmarkTest02632.java new file mode 100644 index 0000000000000000000000000000000000000000..2255aca5d6a71ac06baef5f76e9efba8dba12899 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02632.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02632") +public class BenchmarkTest02632 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02632" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02632" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02632" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = connection.prepareStatement(sql); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02633.java b/OWASP DATASET/BenchmarkTest02633.java new file mode 100644 index 0000000000000000000000000000000000000000..35d6d6aaea84ab4114370262536f293ad8b5f835 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02633.java @@ -0,0 +1,118 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02633") +public class BenchmarkTest02633 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02633" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02633" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02633" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a12213 = param; // assign + StringBuilder b12213 = new StringBuilder(a12213); // stick in stringbuilder + b12213.append(" SafeStuff"); // append some safe content + b12213.replace( + b12213.length() - "Chars".length(), + b12213.length(), + "Chars"); // replace some of the end content + java.util.HashMap map12213 = new java.util.HashMap(); + map12213.put("key12213", b12213.toString()); // put in a collection + String c12213 = (String) map12213.get("key12213"); // get it back out + String d12213 = c12213.substring(0, c12213.length() - 1); // extract most of it + String e12213 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d12213.getBytes()))); // B64 encode and decode it + String f12213 = e12213.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g12213 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g12213); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02634.java b/OWASP DATASET/BenchmarkTest02634.java new file mode 100644 index 0000000000000000000000000000000000000000..9f0a60169d8da1c4729928a25fd7e61f42038e99 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02634.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02634") +public class BenchmarkTest02634 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02634" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02634" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02634" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02635.java b/OWASP DATASET/BenchmarkTest02635.java new file mode 100644 index 0000000000000000000000000000000000000000..4e40f0ede19383ade74705655328ecf69b9202fd --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02635.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02635") +public class BenchmarkTest02635 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02635" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02635" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02635" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02636.java b/OWASP DATASET/BenchmarkTest02636.java new file mode 100644 index 0000000000000000000000000000000000000000..c1e2b610a1c048023d84dab82e7c467403d26299 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02636.java @@ -0,0 +1,107 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02636") +public class BenchmarkTest02636 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02636" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02636" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02636" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, new String[] {"Column1", "Column2"}); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02637.java b/OWASP DATASET/BenchmarkTest02637.java new file mode 100644 index 0000000000000000000000000000000000000000..f830d309c1ad54e7c0ff1dff12cf6575d6e7cb98 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02637.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02637") +public class BenchmarkTest02637 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02637" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02637" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02637" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, new String[] {"Column1", "Column2"}); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02638.java b/OWASP DATASET/BenchmarkTest02638.java new file mode 100644 index 0000000000000000000000000000000000000000..f43320633f81bc868e7fb4c1bce69239f1da1a38 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02638.java @@ -0,0 +1,98 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02638") +public class BenchmarkTest02638 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02638" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02638" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02638" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + // System.out.println("no results for query: " + sql + " because the Spring batchUpdate + // method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02639.java b/OWASP DATASET/BenchmarkTest02639.java new file mode 100644 index 0000000000000000000000000000000000000000..adf75307ae406f90597696ce06f0c92f0b31c88c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02639.java @@ -0,0 +1,118 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02639") +public class BenchmarkTest02639 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02639" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02639" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02639" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.execute(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring execute method doesn't return results."); + + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a57676 = param; // assign + StringBuilder b57676 = new StringBuilder(a57676); // stick in stringbuilder + b57676.append(" SafeStuff"); // append some safe content + b57676.replace( + b57676.length() - "Chars".length(), + b57676.length(), + "Chars"); // replace some of the end content + java.util.HashMap map57676 = new java.util.HashMap(); + map57676.put("key57676", b57676.toString()); // put in a collection + String c57676 = (String) map57676.get("key57676"); // get it back out + String d57676 = c57676.substring(0, c57676.length() - 1); // extract most of it + String e57676 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d57676.getBytes()))); // B64 encode and decode it + String f57676 = e57676.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g57676 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g57676); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02640.java b/OWASP DATASET/BenchmarkTest02640.java new file mode 100644 index 0000000000000000000000000000000000000000..cb1f90a8e2c5b8bbf23da01ff9b85d6f5e1e907f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02640.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02640") +public class BenchmarkTest02640 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02640" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02640" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02640" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.execute(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring execute method doesn't return results."); + + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02641.java b/OWASP DATASET/BenchmarkTest02641.java new file mode 100644 index 0000000000000000000000000000000000000000..5b05102677722324603cec012ed24a44a4421db2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02641.java @@ -0,0 +1,116 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02641") +public class BenchmarkTest02641 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02641" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02641" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02641" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.query( + sql, + new org.springframework.jdbc.core.RowMapper() { + @Override + public String mapRow(java.sql.ResultSet rs, int rowNum) + throws java.sql.SQLException { + try { + return rs.getString("USERNAME"); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper + .hideSQLErrors) { + return "Error processing query."; + } else throw e; + } + } + }); + response.getWriter().println("Your results are: "); + + for (String s : results) { + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(s) + "
"); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02642.java b/OWASP DATASET/BenchmarkTest02642.java new file mode 100644 index 0000000000000000000000000000000000000000..c83ea74914f71073837e4966c70f5d30bbb6a93d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02642.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02642") +public class BenchmarkTest02642 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02642" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02642" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02642" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List> list = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForList(sql); + response.getWriter().println("Your results are:
"); + + // System.out.println("Your results are"); + + for (Object o : list) { + response.getWriter() + .println( + org.owasp.esapi.ESAPI.encoder().encodeForHTML(o.toString()) + + "
"); + // System.out.println(o.toString()); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02643.java b/OWASP DATASET/BenchmarkTest02643.java new file mode 100644 index 0000000000000000000000000000000000000000..4fda89f13ed8afb88583a74899df640a16179c32 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02643.java @@ -0,0 +1,126 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02643") +public class BenchmarkTest02643 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02643" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02643" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02643" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List> list = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForList(sql); + response.getWriter().println("Your results are:
"); + + // System.out.println("Your results are"); + + for (Object o : list) { + response.getWriter() + .println( + org.owasp.esapi.ESAPI.encoder().encodeForHTML(o.toString()) + + "
"); + // System.out.println(o.toString()); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02644.java b/OWASP DATASET/BenchmarkTest02644.java new file mode 100644 index 0000000000000000000000000000000000000000..75ae0a8bef164800935acb1da3cd50f84beb0e38 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02644.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02644") +public class BenchmarkTest02644 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02644" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02644" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02644" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + org.springframework.jdbc.support.rowset.SqlRowSet results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForRowSet(sql); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + while (results.next()) { + response.getWriter() + .println( + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(results.getString("USERNAME")) + + " "); + // System.out.println(results.getString("USERNAME")); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02645.java b/OWASP DATASET/BenchmarkTest02645.java new file mode 100644 index 0000000000000000000000000000000000000000..7d540ce0dffff2ce95b5072ebd141faed9ce385b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02645.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02645") +public class BenchmarkTest02645 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02645" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02645" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02645" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + org.springframework.jdbc.support.rowset.SqlRowSet results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForRowSet(sql); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + while (results.next()) { + response.getWriter() + .println( + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(results.getString("USERNAME")) + + " "); + // System.out.println(results.getString("USERNAME")); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02646.java b/OWASP DATASET/BenchmarkTest02646.java new file mode 100644 index 0000000000000000000000000000000000000000..78c98a8c7fca93d5df91432bedd2086f9735a2ae --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02646.java @@ -0,0 +1,98 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02646") +public class BenchmarkTest02646 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02646" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02646" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02646" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02647.java b/OWASP DATASET/BenchmarkTest02647.java new file mode 100644 index 0000000000000000000000000000000000000000..0b796cc62ffefeb18a0a1fb09fe784164ab54b76 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02647.java @@ -0,0 +1,102 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-05/BenchmarkTest02647") +public class BenchmarkTest02647 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02647" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02647" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02647" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.addBatch(sql); + int[] counts = statement.executeBatch(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(sql, counts, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02648.java b/OWASP DATASET/BenchmarkTest02648.java new file mode 100644 index 0000000000000000000000000000000000000000..d272e74a96a09580c4af78debc0b3551ff728368 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02648.java @@ -0,0 +1,100 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-06/BenchmarkTest02648") +public class BenchmarkTest02648 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02648" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02648" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02648" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map91488 = new java.util.HashMap(); + map91488.put("keyA-91488", "a_Value"); // put some stuff in the collection + map91488.put("keyB-91488", param); // put it in a collection + map91488.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map91488.get("keyB-91488"); // get it back out + bar = (String) map91488.get("keyA-91488"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02649.java b/OWASP DATASET/BenchmarkTest02649.java new file mode 100644 index 0000000000000000000000000000000000000000..6cd490aacb7aa4bfdf1292aa5435e63c5cccb729 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02649.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-06/BenchmarkTest02649") +public class BenchmarkTest02649 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02649" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02649" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02649" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02650.java b/OWASP DATASET/BenchmarkTest02650.java new file mode 100644 index 0000000000000000000000000000000000000000..fcea66e0df784addb86a0f7e03866573556d034b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02650.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-06/BenchmarkTest02650") +public class BenchmarkTest02650 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02650" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02650" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02650" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02651.java b/OWASP DATASET/BenchmarkTest02651.java new file mode 100644 index 0000000000000000000000000000000000000000..27d089d187a2b67ec7404c3b3656b62404808f95 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02651.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-06/BenchmarkTest02651") +public class BenchmarkTest02651 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02651" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02651" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02651" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new String[] {"username", "password"}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02652.java b/OWASP DATASET/BenchmarkTest02652.java new file mode 100644 index 0000000000000000000000000000000000000000..0dd7312ffe03aacfc8697911975bfda963f35e84 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02652.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-06/BenchmarkTest02652") +public class BenchmarkTest02652 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02652" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02652" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02652" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new String[] {"username", "password"}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a25323 = param; // assign + StringBuilder b25323 = new StringBuilder(a25323); // stick in stringbuilder + b25323.append(" SafeStuff"); // append some safe content + b25323.replace( + b25323.length() - "Chars".length(), + b25323.length(), + "Chars"); // replace some of the end content + java.util.HashMap map25323 = new java.util.HashMap(); + map25323.put("key25323", b25323.toString()); // put in a collection + String c25323 = (String) map25323.get("key25323"); // get it back out + String d25323 = c25323.substring(0, c25323.length() - 1); // extract most of it + String e25323 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d25323.getBytes()))); // B64 encode and decode it + String f25323 = e25323.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g25323 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g25323); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02653.java b/OWASP DATASET/BenchmarkTest02653.java new file mode 100644 index 0000000000000000000000000000000000000000..9f93aa1e9fdc5e0695459030a2711d8d7033c745 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02653.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-06/BenchmarkTest02653") +public class BenchmarkTest02653 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02653" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02653" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02653" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + java.sql.ResultSet rs = statement.executeQuery(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(rs, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02654.java b/OWASP DATASET/BenchmarkTest02654.java new file mode 100644 index 0000000000000000000000000000000000000000..d977ceedd341b532f5b7b1794b3e6fd5aaeab9e2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02654.java @@ -0,0 +1,104 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-06/BenchmarkTest02654") +public class BenchmarkTest02654 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02654" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02654" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02654" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02655.java b/OWASP DATASET/BenchmarkTest02655.java new file mode 100644 index 0000000000000000000000000000000000000000..86c4987b7cedd94cdf64bcbda4414d1f42ff2797 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02655.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-06/BenchmarkTest02655") +public class BenchmarkTest02655 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02655" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02655" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02655" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02656.java b/OWASP DATASET/BenchmarkTest02656.java new file mode 100644 index 0000000000000000000000000000000000000000..301a160e55402bacb2961bc4c990a2a85f587bd4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02656.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-06/BenchmarkTest02656") +public class BenchmarkTest02656 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02656" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02656" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02656" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02657.java b/OWASP DATASET/BenchmarkTest02657.java new file mode 100644 index 0000000000000000000000000000000000000000..66dc8b2b985a2ca5ec049f724718c9ba297d577d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02657.java @@ -0,0 +1,99 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-06/BenchmarkTest02657") +public class BenchmarkTest02657 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + String queryString = request.getQueryString(); + String paramval = "BenchmarkTest02657" + "="; + int paramLoc = -1; + if (queryString != null) paramLoc = queryString.indexOf(paramval); + if (paramLoc == -1) { + response.getWriter() + .println( + "getQueryString() couldn't find expected parameter '" + + "BenchmarkTest02657" + + "' in query string."); + return; + } + + String param = + queryString.substring( + paramLoc + + paramval + .length()); // 1st assume "BenchmarkTest02657" param is last + // parameter in query string. + // And then check to see if its in the middle of the query string and if so, trim off what + // comes after. + int ampersandLoc = queryString.indexOf("&", paramLoc); + if (ampersandLoc != -1) { + param = queryString.substring(paramLoc + paramval.length(), ampersandLoc); + } + param = java.net.URLDecoder.decode(param, "UTF-8"); + + String bar = doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02658.java b/OWASP DATASET/BenchmarkTest02658.java new file mode 100644 index 0000000000000000000000000000000000000000..43e605f9e28f363d29bd7c29dc9b1fd16ddfedfb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02658.java @@ -0,0 +1,162 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-03/BenchmarkTest02658") +public class BenchmarkTest02658 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02658"); + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "DES/CBC/PKCS5PADDING", java.security.Security.getProvider("SunJCE")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println( + "Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02659.java b/OWASP DATASET/BenchmarkTest02659.java new file mode 100644 index 0000000000000000000000000000000000000000..0f1e531ad2638e9548feaf4d80c6b07619bd84ce --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02659.java @@ -0,0 +1,158 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-03/BenchmarkTest02659") +public class BenchmarkTest02659 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02659"); + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // AES/GCM example from: + // https://javainterviewpoint.com/java-aes-256-gcm-encryption-and-decryption/ + // 16-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3, + // (byte)0xF3, (byte)0x3C, (byte)0x23, (byte)0xB9, + // (byte)0x9E, (byte)0xC5, (byte)0x77, (byte)0x0B033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(16); + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES/GCM/NOPADDING"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + javax.crypto.spec.GCMParameterSpec paramSpec = + new javax.crypto.spec.GCMParameterSpec(16 * 8, iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.NoSuchPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.IllegalBlockSizeException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (javax.crypto.BadPaddingException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } catch (java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + response.getWriter() + .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02660.java b/OWASP DATASET/BenchmarkTest02660.java new file mode 100644 index 0000000000000000000000000000000000000000..7c7517460906015827e3337981fc36985c3c377a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02660.java @@ -0,0 +1,147 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-03/BenchmarkTest02660") +public class BenchmarkTest02660 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02660"); + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a97788 = param; // assign + StringBuilder b97788 = new StringBuilder(a97788); // stick in stringbuilder + b97788.append(" SafeStuff"); // append some safe content + b97788.replace( + b97788.length() - "Chars".length(), + b97788.length(), + "Chars"); // replace some of the end content + java.util.HashMap map97788 = new java.util.HashMap(); + map97788.put("key97788", b97788.toString()); // put in a collection + String c97788 = (String) map97788.get("key97788"); // get it back out + String d97788 = c97788.substring(0, c97788.length() - 1); // extract most of it + String e97788 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d97788.getBytes()))); // B64 encode and decode it + String f97788 = e97788.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f97788); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02661.java b/OWASP DATASET/BenchmarkTest02661.java new file mode 100644 index 0000000000000000000000000000000000000000..d0f59a771983e91112cbfddfcb6be3dfd3a8d648 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02661.java @@ -0,0 +1,130 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-03/BenchmarkTest02661") +public class BenchmarkTest02661 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02661"); + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + // 8-byte initialization vector + // byte[] iv = { + // (byte)0xB2, (byte)0x12, (byte)0xD5, (byte)0xB2, + // (byte)0x44, (byte)0x21, (byte)0xC3, (byte)0xC3033 + // }; + java.security.SecureRandom random = new java.security.SecureRandom(); + byte[] iv = random.generateSeed(8); // DES requires 8 byte keys + + try { + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("DES/CBC/PKCS5Padding"); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + java.security.spec.AlgorithmParameterSpec paramSpec = + new javax.crypto.spec.IvParameterSpec(iv); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key, paramSpec); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException + | java.security.InvalidAlgorithmParameterException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02662.java b/OWASP DATASET/BenchmarkTest02662.java new file mode 100644 index 0000000000000000000000000000000000000000..231a3fff31eae5704f4735379cd82dd828826738 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02662.java @@ -0,0 +1,120 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-03/BenchmarkTest02662") +public class BenchmarkTest02662 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02662"); + + String bar = doSomething(request, param); + + // Code based on example from: + // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ + + try { + javax.crypto.Cipher c = + javax.crypto.Cipher.getInstance( + "AES/CCM/NoPadding", java.security.Security.getProvider("BC")); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("AES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) bar = param.split(" ")[0]; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02663.java b/OWASP DATASET/BenchmarkTest02663.java new file mode 100644 index 0000000000000000000000000000000000000000..55e4c776850800670b8eabebc4f6349a70071999 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02663.java @@ -0,0 +1,118 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/crypto-03/BenchmarkTest02663") +public class BenchmarkTest02663 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02663"); + + String bar = doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); + javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); + + // Prepare the cipher to encrypt + javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); + c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); + + // encrypt and store the results + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + byte[] result = c.doFinal(input); + + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "secret_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' encrypted and stored
"); + + } catch (java.security.NoSuchAlgorithmException + | javax.crypto.NoSuchPaddingException + | javax.crypto.IllegalBlockSizeException + | javax.crypto.BadPaddingException + | java.security.InvalidKeyException e) { + response.getWriter() + .println( + "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); + e.printStackTrace(response.getWriter()); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02664.java b/OWASP DATASET/BenchmarkTest02664.java new file mode 100644 index 0000000000000000000000000000000000000000..ae604b3b96e66bfe2a1797fe36a84e998f4d2c03 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02664.java @@ -0,0 +1,92 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-03/BenchmarkTest02664") +public class BenchmarkTest02664 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02664"); + + String bar = doSomething(request, param); + + java.io.File fileTarget = new java.io.File(bar, "/Test.txt"); + response.getWriter() + .println( + "Access to file: '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(fileTarget.toString()) + + "' created."); + if (fileTarget.exists()) { + response.getWriter().println(" And file already exists."); + } else { + response.getWriter().println(" But file doesn't exist yet."); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02665.java b/OWASP DATASET/BenchmarkTest02665.java new file mode 100644 index 0000000000000000000000000000000000000000..d6c55f5ba671462dae83997dbf8351aa2c4a0182 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02665.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-03/BenchmarkTest02665") +public class BenchmarkTest02665 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02665"); + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(new java.io.File(fileName)); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + response.getWriter() + .println( + "Problem getting FileInputStream: " + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(e.getMessage())); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02666.java b/OWASP DATASET/BenchmarkTest02666.java new file mode 100644 index 0000000000000000000000000000000000000000..b4aa9af5df687b40e022740c4935a682bc8381b5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02666.java @@ -0,0 +1,96 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-03/BenchmarkTest02666") +public class BenchmarkTest02666 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02666"); + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(fileName); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02667.java b/OWASP DATASET/BenchmarkTest02667.java new file mode 100644 index 0000000000000000000000000000000000000000..5e6eb19daf96858ba529862eed26bd787862995e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02667.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-03/BenchmarkTest02667") +public class BenchmarkTest02667 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02667"); + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileInputStream fis = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + fis = new java.io.FileInputStream(fileName); + byte[] b = new byte[1000]; + int size = fis.read(b); + response.getWriter() + .println( + "The beginning of file: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName) + + "' is:\n\n"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(b, 0, size))); + } catch (Exception e) { + System.out.println("Couldn't open FileInputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fis != null) { + try { + fis.close(); + fis = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02668.java b/OWASP DATASET/BenchmarkTest02668.java new file mode 100644 index 0000000000000000000000000000000000000000..82f322f0a0637a687a944c8ff7c4b04d78f6241f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02668.java @@ -0,0 +1,88 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-03/BenchmarkTest02668") +public class BenchmarkTest02668 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02668"); + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName, false); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map94533 = new java.util.HashMap(); + map94533.put("keyA-94533", "a-Value"); // put some stuff in the collection + map94533.put("keyB-94533", param); // put it in a collection + map94533.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map94533.get("keyB-94533"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02669.java b/OWASP DATASET/BenchmarkTest02669.java new file mode 100644 index 0000000000000000000000000000000000000000..babe6a4d1f22d6a351b7c4985a1eaaf694d3c2a3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02669.java @@ -0,0 +1,93 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/pathtraver-03/BenchmarkTest02669") +public class BenchmarkTest02669 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02669"); + + String bar = doSomething(request, param); + + String fileName = null; + java.io.FileOutputStream fos = null; + + try { + fileName = org.owasp.benchmark.helpers.Utils.TESTFILES_DIR + bar; + + fos = new java.io.FileOutputStream(fileName); + response.getWriter() + .println( + "Now ready to write to file: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(fileName)); + + } catch (Exception e) { + System.out.println("Couldn't open FileOutputStream on file: '" + fileName + "'"); + // System.out.println("File exception caught and swallowed: " + e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + fos = null; + } catch (Exception e) { + // we tried... + } + } + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02670.java b/OWASP DATASET/BenchmarkTest02670.java new file mode 100644 index 0000000000000000000000000000000000000000..b0b3410a8f9becb80caea2bffd1667d12c4663d1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02670.java @@ -0,0 +1,129 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02670") +public class BenchmarkTest02670 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02670"); + + String bar = doSomething(request, param); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("SHA1", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02671.java b/OWASP DATASET/BenchmarkTest02671.java new file mode 100644 index 0000000000000000000000000000000000000000..f0a647c590fc92fc08dd960ff1281b762399b779 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02671.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02671") +public class BenchmarkTest02671 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02671"); + + String bar = doSomething(request, param); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("SHA1", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("SHA1", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map7984 = new java.util.HashMap(); + map7984.put("keyA-7984", "a-Value"); // put some stuff in the collection + map7984.put("keyB-7984", param); // put it in a collection + map7984.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map7984.get("keyB-7984"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02672.java b/OWASP DATASET/BenchmarkTest02672.java new file mode 100644 index 0000000000000000000000000000000000000000..9ba8f1f59000e920724104eb0df01c80687169db --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02672.java @@ -0,0 +1,125 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02672") +public class BenchmarkTest02672 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02672"); + + String bar = doSomething(request, param); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("sha-384", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("sha-384", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map48519 = new java.util.HashMap(); + map48519.put("keyA-48519", "a_Value"); // put some stuff in the collection + map48519.put("keyB-48519", param); // put it in a collection + map48519.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map48519.get("keyB-48519"); // get it back out + bar = (String) map48519.get("keyA-48519"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02673.java b/OWASP DATASET/BenchmarkTest02673.java new file mode 100644 index 0000000000000000000000000000000000000000..5e2a9d14f238d8f7e2e1f127e8ab3bcb3567f880 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02673.java @@ -0,0 +1,123 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02673") +public class BenchmarkTest02673 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02673"); + + String bar = doSomething(request, param); + + java.security.Provider[] provider = java.security.Security.getProviders(); + java.security.MessageDigest md; + + try { + if (provider.length > 1) { + + md = java.security.MessageDigest.getInstance("sha-384", provider[0]); + } else { + md = java.security.MessageDigest.getInstance("sha-384", "SUN"); + } + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } catch (java.security.NoSuchProviderException e) { + System.out.println( + "Problem executing hash - TestCase java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider)"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String,java.security.Provider) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz57216 = new StringBuilder(param); + bar = sbxyz57216.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02674.java b/OWASP DATASET/BenchmarkTest02674.java new file mode 100644 index 0000000000000000000000000000000000000000..2b53ff71dd46b453ce91f9053273a69fd8bd4328 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02674.java @@ -0,0 +1,127 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02674") +public class BenchmarkTest02674 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02674"); + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a73069 = param; // assign + StringBuilder b73069 = new StringBuilder(a73069); // stick in stringbuilder + b73069.append(" SafeStuff"); // append some safe content + b73069.replace( + b73069.length() - "Chars".length(), + b73069.length(), + "Chars"); // replace some of the end content + java.util.HashMap map73069 = new java.util.HashMap(); + map73069.put("key73069", b73069.toString()); // put in a collection + String c73069 = (String) map73069.get("key73069"); // get it back out + String d73069 = c73069.substring(0, c73069.length() - 1); // extract most of it + String e73069 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d73069.getBytes()))); // B64 encode and decode it + String f73069 = e73069.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g73069 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g73069); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02675.java b/OWASP DATASET/BenchmarkTest02675.java new file mode 100644 index 0000000000000000000000000000000000000000..acae665f262a23641305f7b58b511a91e048d571 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02675.java @@ -0,0 +1,109 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02675") +public class BenchmarkTest02675 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02675"); + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02676.java b/OWASP DATASET/BenchmarkTest02676.java new file mode 100644 index 0000000000000000000000000000000000000000..ea3a135bb74db00c09ef9f6a4666e96bcbaa5871 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02676.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02676") +public class BenchmarkTest02676 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02676"); + + String bar = doSomething(request, param); + + try { + java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-256"); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02677.java b/OWASP DATASET/BenchmarkTest02677.java new file mode 100644 index 0000000000000000000000000000000000000000..4a03548e034bd834f3a77930bdce2b9faf5d8a7b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02677.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02677") +public class BenchmarkTest02677 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02677"); + + String bar = doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg1", "SHA512"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz68995 = new StringBuilder(param); + bar = sbxyz68995.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02678.java b/OWASP DATASET/BenchmarkTest02678.java new file mode 100644 index 0000000000000000000000000000000000000000..936d2d004920876fb88eb8f71319d248f121426b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02678.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/hash-02/BenchmarkTest02678") +public class BenchmarkTest02678 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02678"); + + String bar = doSomething(request, param); + + try { + java.util.Properties benchmarkprops = new java.util.Properties(); + benchmarkprops.load( + this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); + String algorithm = benchmarkprops.getProperty("hashAlg2", "SHA5"); + java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm); + byte[] input = {(byte) '?'}; + Object inputParam = bar; + if (inputParam instanceof String) input = ((String) inputParam).getBytes(); + if (inputParam instanceof java.io.InputStream) { + byte[] strInput = new byte[1000]; + int i = ((java.io.InputStream) inputParam).read(strInput); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + input = java.util.Arrays.copyOf(strInput, i); + } + md.update(input); + + byte[] result = md.digest(); + java.io.File fileTarget = + new java.io.File( + new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), + "passwordFile.txt"); + java.io.FileWriter fw = + new java.io.FileWriter(fileTarget, true); // the true will append the new data + fw.write( + "hash_value=" + + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + + "\n"); + fw.close(); + response.getWriter() + .println( + "Sensitive value '" + + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(new String(input)) + + "' hashed and stored
"); + + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing hash - TestCase"); + throw new ServletException(e); + } + + response.getWriter() + .println( + "Hash Test java.security.MessageDigest.getInstance(java.lang.String) executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02679.java b/OWASP DATASET/BenchmarkTest02679.java new file mode 100644 index 0000000000000000000000000000000000000000..62ad5b089fe221640eb61d8ab7a3f60fb299a66a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02679.java @@ -0,0 +1,69 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02679") +public class BenchmarkTest02679 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02679"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + java.io.PrintWriter out = response.getWriter(); + out.write("\n\n\n

"); + out.format(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + out.write("\n

\n\n"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02680.java b/OWASP DATASET/BenchmarkTest02680.java new file mode 100644 index 0000000000000000000000000000000000000000..012069c8869d2abf6c880e2b9928316d56ddf055 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02680.java @@ -0,0 +1,66 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02680") +public class BenchmarkTest02680 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02680"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(java.util.Locale.US, bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02681.java b/OWASP DATASET/BenchmarkTest02681.java new file mode 100644 index 0000000000000000000000000000000000000000..59f80cb8f55c84dafdc2cd95d2ffd514081b66e7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02681.java @@ -0,0 +1,61 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02681") +public class BenchmarkTest02681 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02681"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().format(bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02682.java b/OWASP DATASET/BenchmarkTest02682.java new file mode 100644 index 0000000000000000000000000000000000000000..32927a22f40d8acbf5aac34c60021c86bf2294d3 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02682.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02682") +public class BenchmarkTest02682 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02682"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02683.java b/OWASP DATASET/BenchmarkTest02683.java new file mode 100644 index 0000000000000000000000000000000000000000..cd34b81f86565eb478eca426b99d574e42efa096 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02683.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02683") +public class BenchmarkTest02683 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02683"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a47309 = param; // assign + StringBuilder b47309 = new StringBuilder(a47309); // stick in stringbuilder + b47309.append(" SafeStuff"); // append some safe content + b47309.replace( + b47309.length() - "Chars".length(), + b47309.length(), + "Chars"); // replace some of the end content + java.util.HashMap map47309 = new java.util.HashMap(); + map47309.put("key47309", b47309.toString()); // put in a collection + String c47309 = (String) map47309.get("key47309"); // get it back out + String d47309 = c47309.substring(0, c47309.length() - 1); // extract most of it + String e47309 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d47309.getBytes()))); // B64 encode and decode it + String f47309 = e47309.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g47309 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g47309); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02684.java b/OWASP DATASET/BenchmarkTest02684.java new file mode 100644 index 0000000000000000000000000000000000000000..d5fe38151ec95465433b5aa75ac3d4eb99a191cb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02684.java @@ -0,0 +1,65 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02684") +public class BenchmarkTest02684 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02684"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().print(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02685.java b/OWASP DATASET/BenchmarkTest02685.java new file mode 100644 index 0000000000000000000000000000000000000000..2eec2ae985cd253b3392c4854533b64cc589cec4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02685.java @@ -0,0 +1,68 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02685") +public class BenchmarkTest02685 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02685"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", bar}; + response.getWriter().printf(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02686.java b/OWASP DATASET/BenchmarkTest02686.java new file mode 100644 index 0000000000000000000000000000000000000000..a087e2a3b4f3c249a0c1625ca5cced5dff399587 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02686.java @@ -0,0 +1,67 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02686") +public class BenchmarkTest02686 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02686"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(java.util.Locale.US, bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map36618 = new java.util.HashMap(); + map36618.put("keyA-36618", "a_Value"); // put some stuff in the collection + map36618.put("keyB-36618", param); // put it in a collection + map36618.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map36618.get("keyB-36618"); // get it back out + bar = (String) map36618.get("keyA-36618"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02687.java b/OWASP DATASET/BenchmarkTest02687.java new file mode 100644 index 0000000000000000000000000000000000000000..e1f139b3a84cbfc77eb6e8252487fc3a38f175f6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02687.java @@ -0,0 +1,66 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02687") +public class BenchmarkTest02687 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02687"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(java.util.Locale.US, bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02688.java b/OWASP DATASET/BenchmarkTest02688.java new file mode 100644 index 0000000000000000000000000000000000000000..b006d21ba3a0b273a634060a9d4f6725883d8e61 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02688.java @@ -0,0 +1,61 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02688") +public class BenchmarkTest02688 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02688"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02689.java b/OWASP DATASET/BenchmarkTest02689.java new file mode 100644 index 0000000000000000000000000000000000000000..ece55bb5aa56956d3045c0bd33f08ddb7fa40441 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02689.java @@ -0,0 +1,64 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02689") +public class BenchmarkTest02689 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02689"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02690.java b/OWASP DATASET/BenchmarkTest02690.java new file mode 100644 index 0000000000000000000000000000000000000000..bd138d7cdeed616d1c79b6e39caac50a2ce0a697 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02690.java @@ -0,0 +1,80 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02690") +public class BenchmarkTest02690 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02690"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + Object[] obj = {"a", "b"}; + response.getWriter().printf(bar, obj); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02691.java b/OWASP DATASET/BenchmarkTest02691.java new file mode 100644 index 0000000000000000000000000000000000000000..67a32da60b2df31dcd39dcc9425dd91bc2591ace --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02691.java @@ -0,0 +1,60 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02691") +public class BenchmarkTest02691 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02691"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar.toCharArray()); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02692.java b/OWASP DATASET/BenchmarkTest02692.java new file mode 100644 index 0000000000000000000000000000000000000000..8de38e6e6c11da9001bf314d573651625cdb2c0b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02692.java @@ -0,0 +1,65 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02692") +public class BenchmarkTest02692 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02692"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar.toCharArray()); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02693.java b/OWASP DATASET/BenchmarkTest02693.java new file mode 100644 index 0000000000000000000000000000000000000000..0d963d3e33c9deb7ab9abce27882fe0b1e9a1785 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02693.java @@ -0,0 +1,64 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02693") +public class BenchmarkTest02693 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02693"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz14220 = new StringBuilder(param); + bar = sbxyz14220.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02694.java b/OWASP DATASET/BenchmarkTest02694.java new file mode 100644 index 0000000000000000000000000000000000000000..c880a39ce6c1e2c4a67ccde3a5a16d2be88d8ad0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02694.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02694") +public class BenchmarkTest02694 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02694"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().println(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02695.java b/OWASP DATASET/BenchmarkTest02695.java new file mode 100644 index 0000000000000000000000000000000000000000..3df3df118c42df9c9b2f92ae79523756f16e1382 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02695.java @@ -0,0 +1,70 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02695") +public class BenchmarkTest02695 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02695"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar.toCharArray()); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02696.java b/OWASP DATASET/BenchmarkTest02696.java new file mode 100644 index 0000000000000000000000000000000000000000..70558684e856d45c4ba5770d08df8aaa0ed1a73a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02696.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02696") +public class BenchmarkTest02696 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02696"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write(bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02697.java b/OWASP DATASET/BenchmarkTest02697.java new file mode 100644 index 0000000000000000000000000000000000000000..d13e5b421322a186d234a41399a23d80b28a9a1d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02697.java @@ -0,0 +1,87 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-03/BenchmarkTest02697") +public class BenchmarkTest02697 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02697"); + + String bar = doSomething(request, param); + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(); + + pb.command(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map29916 = new java.util.HashMap(); + map29916.put("keyA-29916", "a-Value"); // put some stuff in the collection + map29916.put("keyB-29916", param); // put it in a collection + map29916.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map29916.get("keyB-29916"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02698.java b/OWASP DATASET/BenchmarkTest02698.java new file mode 100644 index 0000000000000000000000000000000000000000..26e7de5601af437b8e3a0eba0ed2bf7dbf77e8f1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02698.java @@ -0,0 +1,84 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-03/BenchmarkTest02698") +public class BenchmarkTest02698 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02698"); + + String bar = doSomething(request, param); + + java.util.List argList = new java.util.ArrayList(); + + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + argList.add("cmd.exe"); + argList.add("/c"); + } else { + argList.add("sh"); + argList.add("-c"); + } + argList.add("echo " + bar); + + ProcessBuilder pb = new ProcessBuilder(); + + pb.command(argList); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.util.List) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02699.java b/OWASP DATASET/BenchmarkTest02699.java new file mode 100644 index 0000000000000000000000000000000000000000..095d56ccc0abe5e2db723cfcc80f831d87dd3b01 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02699.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-03/BenchmarkTest02699") +public class BenchmarkTest02699 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02699"); + + String bar = doSomething(request, param); + + String a1 = ""; + String a2 = ""; + String osName = System.getProperty("os.name"); + if (osName.indexOf("Windows") != -1) { + a1 = "cmd.exe"; + a2 = "/c"; + } else { + a1 = "sh"; + a2 = "-c"; + } + String[] args = {a1, a2, "echo " + bar}; + + ProcessBuilder pb = new ProcessBuilder(args); + + try { + Process p = pb.start(); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println( + "Problem executing cmdi - java.lang.ProcessBuilder(java.lang.String[]) Test Case"); + throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02700.java b/OWASP DATASET/BenchmarkTest02700.java new file mode 100644 index 0000000000000000000000000000000000000000..49607494676355559b5575ba9f44dfd58811a5b7 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02700.java @@ -0,0 +1,114 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02700") +public class BenchmarkTest02700 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02700"); + + String bar = doSomething(request, param); + + byte[] bytes = new byte[10]; + new java.util.Random().nextBytes(bytes); + String rememberMeKey = org.owasp.esapi.ESAPI.encoder().encodeForBase64(bytes, true); + + String user = "Byron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextBytes() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02701.java b/OWASP DATASET/BenchmarkTest02701.java new file mode 100644 index 0000000000000000000000000000000000000000..d14a928190d4366dc655e3c60176e25030576919 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02701.java @@ -0,0 +1,108 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02701") +public class BenchmarkTest02701 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02701"); + + String bar = doSomething(request, param); + + byte[] bytes = new byte[10]; + new java.util.Random().nextBytes(bytes); + String rememberMeKey = org.owasp.esapi.ESAPI.encoder().encodeForBase64(bytes, true); + + String user = "Byron"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextBytes() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz86795 = new StringBuilder(param); + String bar = sbxyz86795.append("_SafeStuff").toString(); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02702.java b/OWASP DATASET/BenchmarkTest02702.java new file mode 100644 index 0000000000000000000000000000000000000000..307f17905ac67fec0516f4aa154188b46871c229 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02702.java @@ -0,0 +1,111 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-05/BenchmarkTest02702") +public class BenchmarkTest02702 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02702"); + + String bar = doSomething(request, param); + + double value = new java.util.Random().nextDouble(); + String rememberMeKey = Double.toString(value).substring(2); // Trim off the 0. at the front. + + String user = "Donna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02703.java b/OWASP DATASET/BenchmarkTest02703.java new file mode 100644 index 0000000000000000000000000000000000000000..7276ec11ac3a1d5deff23213628c1d0bfe8638a8 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02703.java @@ -0,0 +1,107 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-06/BenchmarkTest02703") +public class BenchmarkTest02703 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02703"); + + String bar = doSomething(request, param); + + float rand = new java.util.Random().nextFloat(); + String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "Floyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz50196 = new StringBuilder(param); + String bar = sbxyz50196.append("_SafeStuff").toString(); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02704.java b/OWASP DATASET/BenchmarkTest02704.java new file mode 100644 index 0000000000000000000000000000000000000000..ddf3192cfb18d5cd9c2268885a719670166a3ad2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02704.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-06/BenchmarkTest02704") +public class BenchmarkTest02704 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02704"); + + String bar = doSomething(request, param); + + float rand = new java.util.Random().nextFloat(); + String rememberMeKey = Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "Floyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setDomain(new java.net.URL(request.getRequestURL().toString()).getHost()); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextFloat() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz82472 = new StringBuilder(param); + bar = sbxyz82472.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02705.java b/OWASP DATASET/BenchmarkTest02705.java new file mode 100644 index 0000000000000000000000000000000000000000..dab01d0ae758eecda25257b8777c78bc18c8df13 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02705.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-06/BenchmarkTest02705") +public class BenchmarkTest02705 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02705"); + + String bar = doSomething(request, param); + + double stuff = new java.util.Random().nextGaussian(); + String rememberMeKey = Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "Gayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter() + .println("Weak Randomness Test java.util.Random.nextGaussian() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + StringBuilder sbxyz10228 = new StringBuilder(param); + bar = sbxyz10228.replace(param.length() - "Z".length(), param.length(), "Z").toString(); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02706.java b/OWASP DATASET/BenchmarkTest02706.java new file mode 100644 index 0000000000000000000000000000000000000000..fa3393bd8a839e80794a7ac3f0460c61eeb9da1d --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02706.java @@ -0,0 +1,112 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-06/BenchmarkTest02706") +public class BenchmarkTest02706 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02706"); + + String bar = doSomething(request, param); + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + bar = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + param.getBytes()))); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02707.java b/OWASP DATASET/BenchmarkTest02707.java new file mode 100644 index 0000000000000000000000000000000000000000..16ac6c47ed97d9094cbff8a6cfb45554abbfc56b --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02707.java @@ -0,0 +1,110 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-06/BenchmarkTest02707") +public class BenchmarkTest02707 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02707"); + + String bar = doSomething(request, param); + + int r = new java.util.Random().nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "Ingrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextInt() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02708.java b/OWASP DATASET/BenchmarkTest02708.java new file mode 100644 index 0000000000000000000000000000000000000000..065a9bf63a3b9b381e7f312a0c59b45beb8efaed --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02708.java @@ -0,0 +1,106 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-06/BenchmarkTest02708") +public class BenchmarkTest02708 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02708"); + + String bar = doSomething(request, param); + + long l = new java.util.Random().nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "Logan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue().equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + + response.getWriter().println("Weak Randomness Test java.util.Random.nextLong() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02709.java b/OWASP DATASET/BenchmarkTest02709.java new file mode 100644 index 0000000000000000000000000000000000000000..47ed1b211d02d25561b119eb485d97a077830f0e --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02709.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest02709") +public class BenchmarkTest02709 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02709"); + + String bar = doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns param to bar on false condition + int num = 106; + + bar = (7 * 42) - num > 200 ? "This should never happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02710.java b/OWASP DATASET/BenchmarkTest02710.java new file mode 100644 index 0000000000000000000000000000000000000000..5abefcf1d9e2e866015af52cc2c5abc293367211 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02710.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest02710") +public class BenchmarkTest02710 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02710"); + + String bar = doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(false); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: false"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02711.java b/OWASP DATASET/BenchmarkTest02711.java new file mode 100644 index 0000000000000000000000000000000000000000..c9712619b289c59b6b3011e0e4f46de9a90014b5 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02711.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/securecookie-00/BenchmarkTest02711") +public class BenchmarkTest02711 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02711"); + + String bar = doSomething(request, param); + + byte[] input = new byte[1000]; + String str = "?"; + Object inputParam = param; + if (inputParam instanceof String) str = ((String) inputParam); + if (inputParam instanceof java.io.InputStream) { + int i = ((java.io.InputStream) inputParam).read(input); + if (i == -1) { + response.getWriter() + .println( + "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); + return; + } + str = new String(input, 0, i); + } + if ("".equals(str)) str = "No cookie value supplied"; + javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("SomeCookie", str); + + cookie.setSecure(true); + cookie.setHttpOnly(true); + cookie.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + response.addCookie(cookie); + + response.getWriter() + .println( + "Created cookie: 'SomeCookie': with value: '" + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(str) + + "' and secure flag set to: true"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02712.java b/OWASP DATASET/BenchmarkTest02712.java new file mode 100644 index 0000000000000000000000000000000000000000..8e75f55fe3b2e981e5e95754142ca8ea532158af --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02712.java @@ -0,0 +1,66 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/xss-05/BenchmarkTest02712") +public class BenchmarkTest02712 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02712"); + + String bar = doSomething(request, param); + + response.setHeader("X-XSS-Protection", "0"); + response.getWriter().write("Parameter value: " + bar); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map52216 = new java.util.HashMap(); + map52216.put("keyA-52216", "a_Value"); // put some stuff in the collection + map52216.put("keyB-52216", param); // put it in a collection + map52216.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map52216.get("keyB-52216"); // get it back out + bar = (String) map52216.get("keyA-52216"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02713.java b/OWASP DATASET/BenchmarkTest02713.java new file mode 100644 index 0000000000000000000000000000000000000000..d6a9cf8b45c24767e2fc665b24943cddcfe65372 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02713.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-03/BenchmarkTest02713") +public class BenchmarkTest02713 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02713"); + + String bar = doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] args = {cmd}; + String[] argsEnv = {bar}; + + Runtime r = Runtime.getRuntime(); + + try { + Process p = r.exec(args, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02714.java b/OWASP DATASET/BenchmarkTest02714.java new file mode 100644 index 0000000000000000000000000000000000000000..6f38a98e7335c2f08135829c33c25276a67e0acb --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02714.java @@ -0,0 +1,82 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/cmdi-03/BenchmarkTest02714") +public class BenchmarkTest02714 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02714"); + + String bar = doSomething(request, param); + + String cmd = + org.owasp.benchmark.helpers.Utils.getInsecureOSCommandString( + this.getClass().getClassLoader()); + String[] argsEnv = {bar}; + Runtime r = Runtime.getRuntime(); + try { + Process p = r.exec(cmd, argsEnv, new java.io.File(System.getProperty("user.dir"))); + org.owasp.benchmark.helpers.Utils.printOSCommandResults(p, response); + } catch (IOException e) { + System.out.println("Problem executing cmdi - TestCase"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); + return; + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02715.java b/OWASP DATASET/BenchmarkTest02715.java new file mode 100644 index 0000000000000000000000000000000000000000..c8988a5a22ef200cd1a11ed0472b15942f919717 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02715.java @@ -0,0 +1,124 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-06/BenchmarkTest02715") +public class BenchmarkTest02715 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02715"); + + String bar = doSomething(request, param); + + try { + double rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextDouble(); + + String rememberMeKey = + Double.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeDonna"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextDouble() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextDouble() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02716.java b/OWASP DATASET/BenchmarkTest02716.java new file mode 100644 index 0000000000000000000000000000000000000000..45e0a535425eb13972be53bd4145e053c13eaa05 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02716.java @@ -0,0 +1,133 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-06/BenchmarkTest02716") +public class BenchmarkTest02716 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02716"); + + String bar = doSomething(request, param); + + try { + float rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextFloat(); + String rememberMeKey = + Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeFloyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextFloat() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextFloat() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a26751 = param; // assign + StringBuilder b26751 = new StringBuilder(a26751); // stick in stringbuilder + b26751.append(" SafeStuff"); // append some safe content + b26751.replace( + b26751.length() - "Chars".length(), + b26751.length(), + "Chars"); // replace some of the end content + java.util.HashMap map26751 = new java.util.HashMap(); + map26751.put("key26751", b26751.toString()); // put in a collection + String c26751 = (String) map26751.get("key26751"); // get it back out + String d26751 = c26751.substring(0, c26751.length() - 1); // extract most of it + String e26751 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d26751.getBytes()))); // B64 encode and decode it + String f26751 = e26751.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g26751 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g26751); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02717.java b/OWASP DATASET/BenchmarkTest02717.java new file mode 100644 index 0000000000000000000000000000000000000000..767d1e84fa14692be5edff718937e9b4a207c023 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02717.java @@ -0,0 +1,115 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-06/BenchmarkTest02717") +public class BenchmarkTest02717 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02717"); + + String bar = doSomething(request, param); + + try { + float rand = java.security.SecureRandom.getInstance("SHA1PRNG").nextFloat(); + String rememberMeKey = + Float.toString(rand).substring(2); // Trim off the 0. at the front. + + String user = "SafeFloyd"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextFloat() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextFloat() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02718.java b/OWASP DATASET/BenchmarkTest02718.java new file mode 100644 index 0000000000000000000000000000000000000000..7e3a8f1056ded2ee8735c50f68c215de51ce024a --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02718.java @@ -0,0 +1,132 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-06/BenchmarkTest02718") +public class BenchmarkTest02718 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02718"); + + String bar = doSomething(request, param); + + try { + double stuff = java.security.SecureRandom.getInstance("SHA1PRNG").nextGaussian(); + String rememberMeKey = + Double.toString(stuff).substring(2); // Trim off the 0. at the front. + + String user = "SafeGayle"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextGaussian() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextGaussian() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a49179 = param; // assign + StringBuilder b49179 = new StringBuilder(a49179); // stick in stringbuilder + b49179.append(" SafeStuff"); // append some safe content + b49179.replace( + b49179.length() - "Chars".length(), + b49179.length(), + "Chars"); // replace some of the end content + java.util.HashMap map49179 = new java.util.HashMap(); + map49179.put("key49179", b49179.toString()); // put in a collection + String c49179 = (String) map49179.get("key49179"); // get it back out + String d49179 = c49179.substring(0, c49179.length() - 1); // extract most of it + String e49179 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d49179.getBytes()))); // B64 encode and decode it + String f49179 = e49179.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(f49179); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02719.java b/OWASP DATASET/BenchmarkTest02719.java new file mode 100644 index 0000000000000000000000000000000000000000..ff4babe3c68eaf908b78575616ce8e43f1a9ef22 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02719.java @@ -0,0 +1,117 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-06/BenchmarkTest02719") +public class BenchmarkTest02719 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02719"); + + String bar = doSomething(request, param); + + try { + int r = java.security.SecureRandom.getInstance("SHA1PRNG").nextInt(); + String rememberMeKey = Integer.toString(r); + + String user = "SafeIngrid"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextInt() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextInt() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map75503 = new java.util.HashMap(); + map75503.put("keyA-75503", "a_Value"); // put some stuff in the collection + map75503.put("keyB-75503", param); // put it in a collection + map75503.put("keyC", "another_Value"); // put some stuff in the collection + bar = (String) map75503.get("keyB-75503"); // get it back out + bar = (String) map75503.get("keyA-75503"); // get safe value back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02720.java b/OWASP DATASET/BenchmarkTest02720.java new file mode 100644 index 0000000000000000000000000000000000000000..0a0a5060efadbd6fb488b47e905865b2e8004f4c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02720.java @@ -0,0 +1,113 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-06/BenchmarkTest02720") +public class BenchmarkTest02720 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02720"); + + String bar = doSomething(request, param); + + try { + long l = java.security.SecureRandom.getInstance("SHA1PRNG").nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "SafeLogan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextLong() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextLong() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02721.java b/OWASP DATASET/BenchmarkTest02721.java new file mode 100644 index 0000000000000000000000000000000000000000..31d4b4a75de9e9a676beeb814a6f6c5919b01224 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02721.java @@ -0,0 +1,111 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/weakrand-06/BenchmarkTest02721") +public class BenchmarkTest02721 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02721"); + + String bar = doSomething(request, param); + + try { + long l = java.security.SecureRandom.getInstance("SHA1PRNG").nextLong(); + String rememberMeKey = Long.toString(l); + + String user = "SafeLogan"; + String fullClassName = this.getClass().getName(); + String testCaseNumber = + fullClassName.substring( + fullClassName.lastIndexOf('.') + 1 + "BenchmarkTest".length()); + user += testCaseNumber; + + String cookieName = "rememberMe" + testCaseNumber; + + boolean foundUser = false; + javax.servlet.http.Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (int i = 0; !foundUser && i < cookies.length; i++) { + javax.servlet.http.Cookie cookie = cookies[i]; + if (cookieName.equals(cookie.getName())) { + if (cookie.getValue() + .equals(request.getSession().getAttribute(cookieName))) { + foundUser = true; + } + } + } + } + + if (foundUser) { + response.getWriter().println("Welcome back: " + user + "
"); + } else { + javax.servlet.http.Cookie rememberMe = + new javax.servlet.http.Cookie(cookieName, rememberMeKey); + rememberMe.setSecure(true); + rememberMe.setHttpOnly(true); + rememberMe.setPath(request.getRequestURI()); // i.e., set path to JUST this servlet + // e.g., /benchmark/sql-01/BenchmarkTest01001 + request.getSession().setAttribute(cookieName, rememberMeKey); + response.addCookie(rememberMe); + response.getWriter() + .println( + user + + " has been remembered with cookie: " + + rememberMe.getName() + + " whose value is: " + + rememberMe.getValue() + + "
"); + } + } catch (java.security.NoSuchAlgorithmException e) { + System.out.println("Problem executing SecureRandom.nextLong() - TestCase"); + throw new ServletException(e); + } + response.getWriter() + .println("Weak Randomness Test java.security.SecureRandom.nextLong() executed"); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.springframework.web.util.HtmlUtils.htmlEscape(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02722.java b/OWASP DATASET/BenchmarkTest02722.java new file mode 100644 index 0000000000000000000000000000000000000000..cc495fa10d2f724da30652227d5eec0454172e03 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02722.java @@ -0,0 +1,66 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest02722") +public class BenchmarkTest02722 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02722"); + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String^,java.lang.Object) + request.getSession().putValue(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: 10340 saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = org.owasp.esapi.ESAPI.encoder().encodeForHTML(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02723.java b/OWASP DATASET/BenchmarkTest02723.java new file mode 100644 index 0000000000000000000000000000000000000000..5de5f75f1985e5077a45bc139617776ee2a32539 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02723.java @@ -0,0 +1,67 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest02723") +public class BenchmarkTest02723 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02723"); + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String^,java.lang.Object) + request.getSession().putValue(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: 10340 saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + StringBuilder sbxyz51151 = new StringBuilder(param); + String bar = sbxyz51151.append("_SafeStuff").toString(); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02724.java b/OWASP DATASET/BenchmarkTest02724.java new file mode 100644 index 0000000000000000000000000000000000000000..e48d0d8a09ec45b8bb90b48330485ba3a197f5ef --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02724.java @@ -0,0 +1,85 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest02724") +public class BenchmarkTest02724 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02724"); + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.putValue(java.lang.String^,java.lang.Object) + request.getSession().putValue(bar, "10340"); + + response.getWriter() + .println( + "Item: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' with value: 10340 saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(2); + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bobs_your_uncle"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bobs_your_uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02725.java b/OWASP DATASET/BenchmarkTest02725.java new file mode 100644 index 0000000000000000000000000000000000000000..1debd0a01421506a34f964ad256dbc3f71d37f9f --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02725.java @@ -0,0 +1,71 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest02725") +public class BenchmarkTest02725 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02725"); + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple ? condition that assigns constant to bar on true condition + int num = 106; + + bar = (7 * 18) + num > 200 ? "This_should_always_happen" : param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02726.java b/OWASP DATASET/BenchmarkTest02726.java new file mode 100644 index 0000000000000000000000000000000000000000..88cc65a0779fe668bf97360d5ce38cadd81004a1 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02726.java @@ -0,0 +1,69 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/trustbound-01/BenchmarkTest02726") +public class BenchmarkTest02726 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02726"); + + String bar = doSomething(request, param); + + // javax.servlet.http.HttpSession.setAttribute(java.lang.String,java.lang.Object^) + request.getSession().setAttribute("userid", bar); + + response.getWriter() + .println( + "Item: 'userid' with value: '" + + org.owasp.benchmark.helpers.Utils.encodeForHTML(bar) + + "' saved in session."); + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + if (param != null && param.length() > 1) { + bar = param.substring(0, param.length() - 1); + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02727.java b/OWASP DATASET/BenchmarkTest02727.java new file mode 100644 index 0000000000000000000000000000000000000000..aec1ee5ed66f2dbada47f09c638ba2ef89757c51 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02727.java @@ -0,0 +1,93 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-06/BenchmarkTest02727") +public class BenchmarkTest02727 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02727"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02728.java b/OWASP DATASET/BenchmarkTest02728.java new file mode 100644 index 0000000000000000000000000000000000000000..c321da721ed3574ca337017166a1191fec5bc4b6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02728.java @@ -0,0 +1,83 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-06/BenchmarkTest02728") +public class BenchmarkTest02728 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02728"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement( + sql, + java.sql.ResultSet.TYPE_FORWARD_ONLY, + java.sql.ResultSet.CONCUR_READ_ONLY, + java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map55235 = new java.util.HashMap(); + map55235.put("keyA-55235", "a-Value"); // put some stuff in the collection + map55235.put("keyB-55235", param); // put it in a collection + map55235.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map55235.get("keyB-55235"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02729.java b/OWASP DATASET/BenchmarkTest02729.java new file mode 100644 index 0000000000000000000000000000000000000000..181c4a4a309440bb41b530eeac70abab84958e31 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02729.java @@ -0,0 +1,79 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-06/BenchmarkTest02729") +public class BenchmarkTest02729 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02729"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, new int[] {1, 2}); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "safe!"; + java.util.HashMap map87005 = new java.util.HashMap(); + map87005.put("keyA-87005", "a-Value"); // put some stuff in the collection + map87005.put("keyB-87005", param); // put it in a collection + map87005.put("keyC", "another-Value"); // put some stuff in the collection + bar = (String) map87005.get("keyB-87005"); // get it back out + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02730.java b/OWASP DATASET/BenchmarkTest02730.java new file mode 100644 index 0000000000000000000000000000000000000000..612f69b00bfb0c6a7c1af48acf8960029d2deefc --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02730.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-06/BenchmarkTest02730") +public class BenchmarkTest02730 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02730"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'"; + + try { + java.sql.Connection connection = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection(); + java.sql.PreparedStatement statement = + connection.prepareStatement(sql, new String[] {"Column1", "Column2"}); + statement.setString(1, "foo"); + statement.execute(); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + // Chain a bunch of propagators in sequence + String a81593 = param; // assign + StringBuilder b81593 = new StringBuilder(a81593); // stick in stringbuilder + b81593.append(" SafeStuff"); // append some safe content + b81593.replace( + b81593.length() - "Chars".length(), + b81593.length(), + "Chars"); // replace some of the end content + java.util.HashMap map81593 = new java.util.HashMap(); + map81593.put("key81593", b81593.toString()); // put in a collection + String c81593 = (String) map81593.get("key81593"); // get it back out + String d81593 = c81593.substring(0, c81593.length() - 1); // extract most of it + String e81593 = + new String( + org.apache.commons.codec.binary.Base64.decodeBase64( + org.apache.commons.codec.binary.Base64.encodeBase64( + d81593.getBytes()))); // B64 encode and decode it + String f81593 = e81593.split(" ")[0]; // split it on a space + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String g81593 = "barbarians_at_the_gate"; // This is static so this whole flow is 'safe' + String bar = thing.doSomething(g81593); // reflection + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02731.java b/OWASP DATASET/BenchmarkTest02731.java new file mode 100644 index 0000000000000000000000000000000000000000..f30d8bba399646cd3fb85f99d78292ee0a311cab --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02731.java @@ -0,0 +1,75 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-06/BenchmarkTest02731") +public class BenchmarkTest02731 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02731"); + + String bar = doSomething(request, param); + + try { + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.batchUpdate(sql); + response.getWriter() + .println( + "No results can be displayed for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql) + + "
" + + " because the Spring batchUpdate method doesn't return results."); + // System.out.println("no results for query: " + sql + " because the Spring batchUpdate + // method doesn't return results."); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02732.java b/OWASP DATASET/BenchmarkTest02732.java new file mode 100644 index 0000000000000000000000000000000000000000..c81f37e173256a97e774679d378b815be92846f0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02732.java @@ -0,0 +1,93 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-06/BenchmarkTest02732") +public class BenchmarkTest02732 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02732"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.query( + sql, + new org.springframework.jdbc.core.RowMapper() { + @Override + public String mapRow(java.sql.ResultSet rs, int rowNum) + throws java.sql.SQLException { + try { + return rs.getString("USERNAME"); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper + .hideSQLErrors) { + return "Error processing query."; + } else throw e; + } + } + }); + response.getWriter().println("Your results are: "); + + for (String s : results) { + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(s) + "
"); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02733.java b/OWASP DATASET/BenchmarkTest02733.java new file mode 100644 index 0000000000000000000000000000000000000000..c46610b1447b52388b5e0fdd4e65db51ca6c1bd6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02733.java @@ -0,0 +1,94 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-06/BenchmarkTest02733") +public class BenchmarkTest02733 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02733"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.List> list = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForList(sql); + response.getWriter().println("Your results are:
"); + + // System.out.println("Your results are"); + + for (Object o : list) { + response.getWriter() + .println( + org.owasp.esapi.ESAPI.encoder().encodeForHTML(o.toString()) + + "
"); + // System.out.println(o.toString()); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02734.java b/OWASP DATASET/BenchmarkTest02734.java new file mode 100644 index 0000000000000000000000000000000000000000..792e7a88383033bbe3d91c21a272c1812991a621 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02734.java @@ -0,0 +1,86 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-06/BenchmarkTest02734") +public class BenchmarkTest02734 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02734"); + + String bar = doSomething(request, param); + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // Long results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForLong(sql); + Long results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Long.class); + response.getWriter().println("Your results are: " + String.valueOf(results)); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02735.java b/OWASP DATASET/BenchmarkTest02735.java new file mode 100644 index 0000000000000000000000000000000000000000..2452dab95712181522999aa9dca7d3a407cc92b4 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02735.java @@ -0,0 +1,95 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-06/BenchmarkTest02735") +public class BenchmarkTest02735 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02735"); + + String bar = doSomething(request, param); + + String sql = "SELECT userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + // Long results = + // org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForLong(sql); + Long results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForObject( + sql, Long.class); + response.getWriter().println("Your results are: " + String.valueOf(results)); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + String guess = "ABC"; + char switchTarget = guess.charAt(1); // condition 'B', which is safe + + // Simple case statement that assigns param to bar on conditions 'A', 'C', or 'D' + switch (switchTarget) { + case 'A': + bar = param; + break; + case 'B': + bar = "bob"; + break; + case 'C': + case 'D': + bar = param; + break; + default: + bar = "bob's your uncle"; + break; + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02736.java b/OWASP DATASET/BenchmarkTest02736.java new file mode 100644 index 0000000000000000000000000000000000000000..88f3add43e74fd7f990955d42543c8859bfae7d6 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02736.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-06/BenchmarkTest02736") +public class BenchmarkTest02736 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02736"); + + String bar = doSomething(request, param); + + String sql = + "SELECT TOP 1 userid from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + java.util.Map results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForMap(sql); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + response.getWriter() + .println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(results.toString())); + // System.out.println(results.toString()); + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + org.owasp.benchmark.helpers.ThingInterface thing = + org.owasp.benchmark.helpers.ThingFactory.createThing(); + String bar = thing.doSomething(param); + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02737.java b/OWASP DATASET/BenchmarkTest02737.java new file mode 100644 index 0000000000000000000000000000000000000000..132861fb46ac3b7bdfc94978eb6358e9b4bea56c --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02737.java @@ -0,0 +1,91 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-06/BenchmarkTest02737") +public class BenchmarkTest02737 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02737"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + try { + org.springframework.jdbc.support.rowset.SqlRowSet results = + org.owasp.benchmark.helpers.DatabaseHelper.JDBCtemplate.queryForRowSet(sql); + response.getWriter().println("Your results are: "); + + // System.out.println("Your results are"); + while (results.next()) { + response.getWriter() + .println( + org.owasp + .esapi + .ESAPI + .encoder() + .encodeForHTML(results.getString("USERNAME")) + + " "); + // System.out.println(results.getString("USERNAME")); + } + } catch (org.springframework.dao.EmptyResultDataAccessException e) { + response.getWriter() + .println( + "No results returned for query: " + + org.owasp.esapi.ESAPI.encoder().encodeForHTML(sql)); + } catch (org.springframework.dao.DataAccessException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns constant to bar on true condition + int num = 86; + if ((7 * 42) - num > 200) bar = "This_should_always_happen"; + else bar = param; + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02738.java b/OWASP DATASET/BenchmarkTest02738.java new file mode 100644 index 0000000000000000000000000000000000000000..7fb69c2e4b0d3dcc7e755b479d70104efd7cdfc2 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02738.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-06/BenchmarkTest02738") +public class BenchmarkTest02738 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02738"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = "alsosafe"; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(1); // get the last 'safe' value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02739.java b/OWASP DATASET/BenchmarkTest02739.java new file mode 100644 index 0000000000000000000000000000000000000000..3c57c2e53468f8181cf8e49ab7fa59052ae421f0 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02739.java @@ -0,0 +1,81 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-06/BenchmarkTest02739") +public class BenchmarkTest02739 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02739"); + + String bar = doSomething(request, param); + + String sql = "SELECT * from USERS where USERNAME='foo' and PASSWORD='" + bar + "'"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + statement.execute(sql, new int[] {1, 2}); + org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar = ""; + if (param != null) { + java.util.List valuesList = new java.util.ArrayList(); + valuesList.add("safe"); + valuesList.add(param); + valuesList.add("moresafe"); + + valuesList.remove(0); // remove the 1st safe value + + bar = valuesList.get(0); // get the param value + } + + return bar; + } +} diff --git a/OWASP DATASET/BenchmarkTest02740.java b/OWASP DATASET/BenchmarkTest02740.java new file mode 100644 index 0000000000000000000000000000000000000000..b573cfc1561b1bfb7db84a0537f7d1494a959461 --- /dev/null +++ b/OWASP DATASET/BenchmarkTest02740.java @@ -0,0 +1,76 @@ +/** + * OWASP Benchmark Project v1.2 + * + *

This file is part of the Open Web Application Security Project (OWASP) Benchmark Project. For + * details, please see https://owasp.org/www-project-benchmark/. + * + *

The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Foundation, version 2. + * + *

The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * @author Nick Sanidas + * @created 2015 + */ +package org.owasp.benchmark.testcode; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(value = "/sqli-06/BenchmarkTest02740") +public class BenchmarkTest02740 extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + + org.owasp.benchmark.helpers.SeparateClassRequest scr = + new org.owasp.benchmark.helpers.SeparateClassRequest(request); + String param = scr.getTheValue("BenchmarkTest02740"); + + String bar = doSomething(request, param); + + String sql = "INSERT INTO users (username, password) VALUES ('foo','" + bar + "')"; + + try { + java.sql.Statement statement = + org.owasp.benchmark.helpers.DatabaseHelper.getSqlStatement(); + int count = statement.executeUpdate(sql); + org.owasp.benchmark.helpers.DatabaseHelper.outputUpdateComplete(sql, response); + } catch (java.sql.SQLException e) { + if (org.owasp.benchmark.helpers.DatabaseHelper.hideSQLErrors) { + response.getWriter().println("Error processing request."); + return; + } else throw new ServletException(e); + } + } // end doPost + + private static String doSomething(HttpServletRequest request, String param) + throws ServletException, IOException { + + String bar; + + // Simple if statement that assigns param to bar on true condition + int num = 196; + if ((500 / 42) + num > 200) bar = param; + else bar = "This should never happen"; + + return bar; + } +} diff --git a/OWASP DATASET/expectedresults-1.2.csv b/OWASP DATASET/expectedresults-1.2.csv new file mode 100644 index 0000000000000000000000000000000000000000..f23eeced4626da5597a1e182942d43e874c3a53f --- /dev/null +++ b/OWASP DATASET/expectedresults-1.2.csv @@ -0,0 +1,2741 @@ +# test name, category, real vulnerability, cwe, Benchmark version: 1.2, 2016-06-1 +BenchmarkTest00001,pathtraver,true,22 +BenchmarkTest00002,pathtraver,true,22 +BenchmarkTest00003,hash,true,328 +BenchmarkTest00004,trustbound,true,501 +BenchmarkTest00005,crypto,true,327 +BenchmarkTest00006,cmdi,true,78 +BenchmarkTest00007,cmdi,true,78 +BenchmarkTest00008,sqli,true,89 +BenchmarkTest00009,hash,false,328 +BenchmarkTest00010,weakrand,false,330 +BenchmarkTest00011,pathtraver,true,22 +BenchmarkTest00012,ldapi,true,90 +BenchmarkTest00013,xss,true,79 +BenchmarkTest00014,xss,true,79 +BenchmarkTest00015,cmdi,true,78 +BenchmarkTest00016,securecookie,false,614 +BenchmarkTest00017,cmdi,true,78 +BenchmarkTest00018,sqli,true,89 +BenchmarkTest00019,crypto,true,327 +BenchmarkTest00020,crypto,true,327 +BenchmarkTest00021,ldapi,true,90 +BenchmarkTest00022,hash,false,328 +BenchmarkTest00023,weakrand,true,330 +BenchmarkTest00024,sqli,true,89 +BenchmarkTest00025,sqli,true,89 +BenchmarkTest00026,sqli,true,89 +BenchmarkTest00027,sqli,true,89 +BenchmarkTest00028,pathtraver,true,22 +BenchmarkTest00029,hash,true,328 +BenchmarkTest00030,xss,true,79 +BenchmarkTest00031,trustbound,true,501 +BenchmarkTest00032,sqli,true,89 +BenchmarkTest00033,sqli,true,89 +BenchmarkTest00034,sqli,true,89 +BenchmarkTest00035,crypto,true,327 +BenchmarkTest00036,xss,true,79 +BenchmarkTest00037,sqli,true,89 +BenchmarkTest00038,sqli,true,89 +BenchmarkTest00039,sqli,true,89 +BenchmarkTest00040,pathtraver,true,22 +BenchmarkTest00041,xss,true,79 +BenchmarkTest00042,weakrand,false,330 +BenchmarkTest00043,sqli,true,89 +BenchmarkTest00044,ldapi,true,90 +BenchmarkTest00045,pathtraver,true,22 +BenchmarkTest00046,hash,true,328 +BenchmarkTest00047,xss,true,79 +BenchmarkTest00048,xss,true,79 +BenchmarkTest00049,xss,true,79 +BenchmarkTest00050,crypto,true,327 +BenchmarkTest00051,cmdi,false,78 +BenchmarkTest00052,sqli,false,89 +BenchmarkTest00053,crypto,true,327 +BenchmarkTest00054,crypto,false,327 +BenchmarkTest00055,crypto,true,327 +BenchmarkTest00056,crypto,true,327 +BenchmarkTest00057,crypto,true,327 +BenchmarkTest00058,crypto,false,327 +BenchmarkTest00059,crypto,false,327 +BenchmarkTest00060,pathtraver,true,22 +BenchmarkTest00061,pathtraver,true,22 +BenchmarkTest00062,pathtraver,true,22 +BenchmarkTest00063,pathtraver,false,22 +BenchmarkTest00064,pathtraver,false,22 +BenchmarkTest00065,pathtraver,true,22 +BenchmarkTest00066,weakrand,true,330 +BenchmarkTest00067,weakrand,true,330 +BenchmarkTest00068,weakrand,true,330 +BenchmarkTest00069,hash,false,328 +BenchmarkTest00070,hash,true,328 +BenchmarkTest00071,hash,true,328 +BenchmarkTest00072,hash,false,328 +BenchmarkTest00073,hash,true,328 +BenchmarkTest00074,hash,true,328 +BenchmarkTest00075,hash,false,328 +BenchmarkTest00076,hash,false,328 +BenchmarkTest00077,cmdi,true,78 +BenchmarkTest00078,weakrand,true,330 +BenchmarkTest00079,weakrand,true,330 +BenchmarkTest00080,weakrand,true,330 +BenchmarkTest00081,weakrand,true,330 +BenchmarkTest00082,weakrand,true,330 +BenchmarkTest00083,weakrand,true,330 +BenchmarkTest00084,weakrand,true,330 +BenchmarkTest00085,weakrand,true,330 +BenchmarkTest00086,weakrand,true,330 +BenchmarkTest00087,securecookie,true,614 +BenchmarkTest00088,securecookie,false,614 +BenchmarkTest00089,securecookie,false,614 +BenchmarkTest00090,cmdi,false,78 +BenchmarkTest00091,cmdi,true,78 +BenchmarkTest00092,cmdi,true,78 +BenchmarkTest00093,cmdi,false,78 +BenchmarkTest00094,weakrand,false,330 +BenchmarkTest00095,weakrand,false,330 +BenchmarkTest00096,weakrand,false,330 +BenchmarkTest00097,trustbound,false,501 +BenchmarkTest00098,trustbound,true,501 +BenchmarkTest00099,trustbound,false,501 +BenchmarkTest00100,sqli,true,89 +BenchmarkTest00101,sqli,true,89 +BenchmarkTest00102,sqli,true,89 +BenchmarkTest00103,sqli,true,89 +BenchmarkTest00104,sqli,false,89 +BenchmarkTest00105,sqli,false,89 +BenchmarkTest00106,sqli,true,89 +BenchmarkTest00107,sqli,false,89 +BenchmarkTest00108,sqli,true,89 +BenchmarkTest00109,sqli,true,89 +BenchmarkTest00110,sqli,false,89 +BenchmarkTest00111,sqli,true,89 +BenchmarkTest00112,sqli,true,89 +BenchmarkTest00113,sqli,false,89 +BenchmarkTest00114,sqli,false,89 +BenchmarkTest00115,sqli,true,89 +BenchmarkTest00116,xpathi,false,643 +BenchmarkTest00117,xpathi,false,643 +BenchmarkTest00118,xpathi,false,643 +BenchmarkTest00119,crypto,true,327 +BenchmarkTest00120,crypto,true,327 +BenchmarkTest00121,crypto,false,327 +BenchmarkTest00122,crypto,false,327 +BenchmarkTest00123,crypto,true,327 +BenchmarkTest00124,crypto,true,327 +BenchmarkTest00125,crypto,true,327 +BenchmarkTest00126,crypto,false,327 +BenchmarkTest00127,crypto,false,327 +BenchmarkTest00128,crypto,false,327 +BenchmarkTest00129,crypto,false,327 +BenchmarkTest00130,crypto,false,327 +BenchmarkTest00131,pathtraver,false,22 +BenchmarkTest00132,pathtraver,false,22 +BenchmarkTest00133,pathtraver,true,22 +BenchmarkTest00134,pathtraver,false,22 +BenchmarkTest00135,pathtraver,false,22 +BenchmarkTest00136,pathtraver,false,22 +BenchmarkTest00137,pathtraver,false,22 +BenchmarkTest00138,ldapi,false,90 +BenchmarkTest00139,ldapi,false,90 +BenchmarkTest00140,weakrand,true,330 +BenchmarkTest00141,hash,true,328 +BenchmarkTest00142,hash,false,328 +BenchmarkTest00143,hash,true,328 +BenchmarkTest00144,xss,true,79 +BenchmarkTest00145,xss,true,79 +BenchmarkTest00146,xss,true,79 +BenchmarkTest00147,xss,false,79 +BenchmarkTest00148,xss,true,79 +BenchmarkTest00149,xss,true,79 +BenchmarkTest00150,xss,true,79 +BenchmarkTest00151,xss,false,79 +BenchmarkTest00152,xss,true,79 +BenchmarkTest00153,xss,true,79 +BenchmarkTest00154,xss,true,79 +BenchmarkTest00155,xss,true,79 +BenchmarkTest00156,xss,true,79 +BenchmarkTest00157,xss,true,79 +BenchmarkTest00158,cmdi,false,78 +BenchmarkTest00159,cmdi,true,78 +BenchmarkTest00160,weakrand,true,330 +BenchmarkTest00161,weakrand,true,330 +BenchmarkTest00162,weakrand,true,330 +BenchmarkTest00163,weakrand,true,330 +BenchmarkTest00164,weakrand,true,330 +BenchmarkTest00165,weakrand,true,330 +BenchmarkTest00166,weakrand,true,330 +BenchmarkTest00167,weakrand,true,330 +BenchmarkTest00168,weakrand,true,330 +BenchmarkTest00169,securecookie,true,614 +BenchmarkTest00170,securecookie,true,614 +BenchmarkTest00171,cmdi,false,78 +BenchmarkTest00172,cmdi,true,78 +BenchmarkTest00173,cmdi,true,78 +BenchmarkTest00174,cmdi,true,78 +BenchmarkTest00175,cmdi,false,78 +BenchmarkTest00176,cmdi,true,78 +BenchmarkTest00177,cmdi,false,78 +BenchmarkTest00178,weakrand,false,330 +BenchmarkTest00179,weakrand,false,330 +BenchmarkTest00180,weakrand,false,330 +BenchmarkTest00181,weakrand,false,330 +BenchmarkTest00182,weakrand,false,330 +BenchmarkTest00183,weakrand,false,330 +BenchmarkTest00184,weakrand,false,330 +BenchmarkTest00185,weakrand,false,330 +BenchmarkTest00186,weakrand,false,330 +BenchmarkTest00187,weakrand,false,330 +BenchmarkTest00188,weakrand,false,330 +BenchmarkTest00189,trustbound,false,501 +BenchmarkTest00190,sqli,false,89 +BenchmarkTest00191,sqli,false,89 +BenchmarkTest00192,sqli,true,89 +BenchmarkTest00193,sqli,true,89 +BenchmarkTest00194,sqli,true,89 +BenchmarkTest00195,sqli,true,89 +BenchmarkTest00196,sqli,true,89 +BenchmarkTest00197,sqli,false,89 +BenchmarkTest00198,sqli,true,89 +BenchmarkTest00199,sqli,true,89 +BenchmarkTest00200,sqli,false,89 +BenchmarkTest00201,sqli,false,89 +BenchmarkTest00202,sqli,false,89 +BenchmarkTest00203,sqli,true,89 +BenchmarkTest00204,sqli,true,89 +BenchmarkTest00205,sqli,false,89 +BenchmarkTest00206,sqli,false,89 +BenchmarkTest00207,xpathi,true,643 +BenchmarkTest00208,crypto,true,327 +BenchmarkTest00209,crypto,false,327 +BenchmarkTest00210,crypto,true,327 +BenchmarkTest00211,crypto,false,327 +BenchmarkTest00212,crypto,false,327 +BenchmarkTest00213,crypto,false,327 +BenchmarkTest00214,crypto,false,327 +BenchmarkTest00215,pathtraver,true,22 +BenchmarkTest00216,pathtraver,true,22 +BenchmarkTest00217,pathtraver,false,22 +BenchmarkTest00218,pathtraver,true,22 +BenchmarkTest00219,pathtraver,true,22 +BenchmarkTest00220,pathtraver,false,22 +BenchmarkTest00221,pathtraver,false,22 +BenchmarkTest00222,pathtraver,true,22 +BenchmarkTest00223,hash,true,328 +BenchmarkTest00224,hash,false,328 +BenchmarkTest00225,hash,false,328 +BenchmarkTest00226,hash,true,328 +BenchmarkTest00227,hash,true,328 +BenchmarkTest00228,hash,false,328 +BenchmarkTest00229,hash,false,328 +BenchmarkTest00230,weakrand,true,330 +BenchmarkTest00231,weakrand,true,330 +BenchmarkTest00232,weakrand,true,330 +BenchmarkTest00233,weakrand,true,330 +BenchmarkTest00234,weakrand,true,330 +BenchmarkTest00235,weakrand,true,330 +BenchmarkTest00236,weakrand,true,330 +BenchmarkTest00237,weakrand,true,330 +BenchmarkTest00238,weakrand,true,330 +BenchmarkTest00239,weakrand,true,330 +BenchmarkTest00240,weakrand,true,330 +BenchmarkTest00241,securecookie,true,614 +BenchmarkTest00242,securecookie,false,614 +BenchmarkTest00243,weakrand,false,330 +BenchmarkTest00244,weakrand,false,330 +BenchmarkTest00245,weakrand,false,330 +BenchmarkTest00246,weakrand,false,330 +BenchmarkTest00247,weakrand,false,330 +BenchmarkTest00248,weakrand,false,330 +BenchmarkTest00249,weakrand,false,330 +BenchmarkTest00250,trustbound,false,501 +BenchmarkTest00251,trustbound,true,501 +BenchmarkTest00252,trustbound,false,501 +BenchmarkTest00253,trustbound,false,501 +BenchmarkTest00254,crypto,true,327 +BenchmarkTest00255,crypto,false,327 +BenchmarkTest00256,crypto,true,327 +BenchmarkTest00257,crypto,true,327 +BenchmarkTest00258,crypto,true,327 +BenchmarkTest00259,crypto,false,327 +BenchmarkTest00260,crypto,false,327 +BenchmarkTest00261,pathtraver,false,22 +BenchmarkTest00262,pathtraver,true,22 +BenchmarkTest00263,pathtraver,false,22 +BenchmarkTest00264,pathtraver,true,22 +BenchmarkTest00265,pathtraver,false,22 +BenchmarkTest00266,hash,true,328 +BenchmarkTest00267,hash,true,328 +BenchmarkTest00268,hash,true,328 +BenchmarkTest00269,hash,true,328 +BenchmarkTest00270,hash,false,328 +BenchmarkTest00271,hash,false,328 +BenchmarkTest00272,hash,true,328 +BenchmarkTest00273,hash,true,328 +BenchmarkTest00274,hash,true,328 +BenchmarkTest00275,xss,false,79 +BenchmarkTest00276,xss,true,79 +BenchmarkTest00277,xss,false,79 +BenchmarkTest00278,xss,false,79 +BenchmarkTest00279,xss,true,79 +BenchmarkTest00280,xss,true,79 +BenchmarkTest00281,xss,false,79 +BenchmarkTest00282,xss,false,79 +BenchmarkTest00283,xss,false,79 +BenchmarkTest00284,xss,true,79 +BenchmarkTest00285,xss,false,79 +BenchmarkTest00286,xss,false,79 +BenchmarkTest00287,xss,true,79 +BenchmarkTest00288,xss,false,79 +BenchmarkTest00289,xss,false,79 +BenchmarkTest00290,xss,true,79 +BenchmarkTest00291,xss,true,79 +BenchmarkTest00292,xss,true,79 +BenchmarkTest00293,cmdi,true,78 +BenchmarkTest00294,cmdi,true,78 +BenchmarkTest00295,cmdi,true,78 +BenchmarkTest00296,weakrand,true,330 +BenchmarkTest00297,weakrand,true,330 +BenchmarkTest00298,weakrand,true,330 +BenchmarkTest00299,weakrand,true,330 +BenchmarkTest00300,securecookie,true,614 +BenchmarkTest00301,xss,true,79 +BenchmarkTest00302,cmdi,true,78 +BenchmarkTest00303,cmdi,true,78 +BenchmarkTest00304,cmdi,true,78 +BenchmarkTest00305,cmdi,false,78 +BenchmarkTest00306,cmdi,true,78 +BenchmarkTest00307,cmdi,false,78 +BenchmarkTest00308,cmdi,false,78 +BenchmarkTest00309,cmdi,false,78 +BenchmarkTest00310,cmdi,false,78 +BenchmarkTest00311,cmdi,true,78 +BenchmarkTest00312,weakrand,false,330 +BenchmarkTest00313,weakrand,false,330 +BenchmarkTest00314,weakrand,false,330 +BenchmarkTest00315,weakrand,false,330 +BenchmarkTest00316,weakrand,false,330 +BenchmarkTest00317,weakrand,false,330 +BenchmarkTest00318,weakrand,false,330 +BenchmarkTest00319,weakrand,false,330 +BenchmarkTest00320,weakrand,false,330 +BenchmarkTest00321,trustbound,true,501 +BenchmarkTest00322,trustbound,false,501 +BenchmarkTest00323,trustbound,false,501 +BenchmarkTest00324,trustbound,true,501 +BenchmarkTest00325,trustbound,true,501 +BenchmarkTest00326,trustbound,true,501 +BenchmarkTest00327,trustbound,true,501 +BenchmarkTest00328,sqli,true,89 +BenchmarkTest00329,sqli,false,89 +BenchmarkTest00330,sqli,false,89 +BenchmarkTest00331,sqli,false,89 +BenchmarkTest00332,sqli,false,89 +BenchmarkTest00333,sqli,false,89 +BenchmarkTest00334,sqli,false,89 +BenchmarkTest00335,sqli,true,89 +BenchmarkTest00336,sqli,false,89 +BenchmarkTest00337,sqli,true,89 +BenchmarkTest00338,sqli,false,89 +BenchmarkTest00339,sqli,true,89 +BenchmarkTest00340,sqli,false,89 +BenchmarkTest00341,sqli,true,89 +BenchmarkTest00342,sqli,true,89 +BenchmarkTest00343,sqli,false,89 +BenchmarkTest00344,sqli,false,89 +BenchmarkTest00345,crypto,false,327 +BenchmarkTest00346,hash,true,328 +BenchmarkTest00347,weakrand,true,330 +BenchmarkTest00348,securecookie,true,614 +BenchmarkTest00349,weakrand,false,330 +BenchmarkTest00350,crypto,false,327 +BenchmarkTest00351,crypto,false,327 +BenchmarkTest00352,crypto,false,327 +BenchmarkTest00353,crypto,false,327 +BenchmarkTest00354,crypto,true,327 +BenchmarkTest00355,crypto,true,327 +BenchmarkTest00356,crypto,true,327 +BenchmarkTest00357,crypto,false,327 +BenchmarkTest00358,crypto,false,327 +BenchmarkTest00359,pathtraver,true,22 +BenchmarkTest00360,pathtraver,true,22 +BenchmarkTest00361,pathtraver,false,22 +BenchmarkTest00362,pathtraver,true,22 +BenchmarkTest00363,pathtraver,true,22 +BenchmarkTest00364,pathtraver,false,22 +BenchmarkTest00365,pathtraver,false,22 +BenchmarkTest00366,pathtraver,false,22 +BenchmarkTest00367,ldapi,false,90 +BenchmarkTest00368,weakrand,true,330 +BenchmarkTest00369,weakrand,true,330 +BenchmarkTest00370,hash,false,328 +BenchmarkTest00371,hash,true,328 +BenchmarkTest00372,hash,true,328 +BenchmarkTest00373,hash,false,328 +BenchmarkTest00374,hash,true,328 +BenchmarkTest00375,xss,true,79 +BenchmarkTest00376,xss,true,79 +BenchmarkTest00377,xss,false,79 +BenchmarkTest00378,xss,true,79 +BenchmarkTest00379,xss,false,79 +BenchmarkTest00380,xss,true,79 +BenchmarkTest00381,xss,false,79 +BenchmarkTest00382,xss,true,79 +BenchmarkTest00383,xss,true,79 +BenchmarkTest00384,xss,true,79 +BenchmarkTest00385,xss,true,79 +BenchmarkTest00386,xss,false,79 +BenchmarkTest00387,xss,true,79 +BenchmarkTest00388,xss,true,79 +BenchmarkTest00389,xss,false,79 +BenchmarkTest00390,xss,true,79 +BenchmarkTest00391,xss,false,79 +BenchmarkTest00392,xss,true,79 +BenchmarkTest00393,xss,false,79 +BenchmarkTest00394,xss,false,79 +BenchmarkTest00395,xss,true,79 +BenchmarkTest00396,cmdi,false,78 +BenchmarkTest00397,weakrand,true,330 +BenchmarkTest00398,weakrand,true,330 +BenchmarkTest00399,weakrand,true,330 +BenchmarkTest00400,weakrand,true,330 +BenchmarkTest00401,weakrand,true,330 +BenchmarkTest00402,weakrand,true,330 +BenchmarkTest00403,securecookie,true,614 +BenchmarkTest00404,securecookie,false,614 +BenchmarkTest00405,securecookie,false,614 +BenchmarkTest00406,cmdi,false,78 +BenchmarkTest00407,cmdi,true,78 +BenchmarkTest00408,cmdi,false,78 +BenchmarkTest00409,cmdi,true,78 +BenchmarkTest00410,cmdi,false,78 +BenchmarkTest00411,cmdi,false,78 +BenchmarkTest00412,cmdi,false,78 +BenchmarkTest00413,weakrand,false,330 +BenchmarkTest00414,weakrand,false,330 +BenchmarkTest00415,weakrand,false,330 +BenchmarkTest00416,weakrand,false,330 +BenchmarkTest00417,weakrand,false,330 +BenchmarkTest00418,weakrand,false,330 +BenchmarkTest00419,weakrand,false,330 +BenchmarkTest00420,weakrand,false,330 +BenchmarkTest00421,weakrand,false,330 +BenchmarkTest00422,weakrand,false,330 +BenchmarkTest00423,weakrand,false,330 +BenchmarkTest00424,trustbound,true,501 +BenchmarkTest00425,trustbound,true,501 +BenchmarkTest00426,trustbound,true,501 +BenchmarkTest00427,trustbound,true,501 +BenchmarkTest00428,sqli,true,89 +BenchmarkTest00429,sqli,true,89 +BenchmarkTest00430,sqli,false,89 +BenchmarkTest00431,sqli,true,89 +BenchmarkTest00432,sqli,false,89 +BenchmarkTest00433,sqli,true,89 +BenchmarkTest00434,sqli,true,89 +BenchmarkTest00435,sqli,true,89 +BenchmarkTest00436,sqli,false,89 +BenchmarkTest00437,sqli,false,89 +BenchmarkTest00438,sqli,true,89 +BenchmarkTest00439,sqli,true,89 +BenchmarkTest00440,sqli,false,89 +BenchmarkTest00441,sqli,true,89 +BenchmarkTest00442,xpathi,true,643 +BenchmarkTest00443,crypto,false,327 +BenchmarkTest00444,crypto,false,327 +BenchmarkTest00445,crypto,true,327 +BenchmarkTest00446,crypto,true,327 +BenchmarkTest00447,crypto,false,327 +BenchmarkTest00448,crypto,true,327 +BenchmarkTest00449,crypto,true,327 +BenchmarkTest00450,crypto,false,327 +BenchmarkTest00451,crypto,false,327 +BenchmarkTest00452,pathtraver,true,22 +BenchmarkTest00453,pathtraver,true,22 +BenchmarkTest00454,pathtraver,false,22 +BenchmarkTest00455,pathtraver,true,22 +BenchmarkTest00456,pathtraver,true,22 +BenchmarkTest00457,pathtraver,true,22 +BenchmarkTest00458,pathtraver,false,22 +BenchmarkTest00459,pathtraver,true,22 +BenchmarkTest00460,pathtraver,false,22 +BenchmarkTest00461,weakrand,true,330 +BenchmarkTest00462,hash,true,328 +BenchmarkTest00463,hash,false,328 +BenchmarkTest00464,hash,true,328 +BenchmarkTest00465,hash,true,328 +BenchmarkTest00466,hash,false,328 +BenchmarkTest00467,xss,true,79 +BenchmarkTest00468,xss,false,79 +BenchmarkTest00469,xss,false,79 +BenchmarkTest00470,xss,false,79 +BenchmarkTest00471,xss,false,79 +BenchmarkTest00472,xss,true,79 +BenchmarkTest00473,xss,true,79 +BenchmarkTest00474,xss,false,79 +BenchmarkTest00475,xss,true,79 +BenchmarkTest00476,xss,false,79 +BenchmarkTest00477,xss,true,79 +BenchmarkTest00478,xss,true,79 +BenchmarkTest00479,xss,false,79 +BenchmarkTest00480,cmdi,true,78 +BenchmarkTest00481,cmdi,false,78 +BenchmarkTest00482,weakrand,true,330 +BenchmarkTest00483,weakrand,true,330 +BenchmarkTest00484,weakrand,true,330 +BenchmarkTest00485,weakrand,true,330 +BenchmarkTest00486,weakrand,true,330 +BenchmarkTest00487,weakrand,true,330 +BenchmarkTest00488,weakrand,true,330 +BenchmarkTest00489,weakrand,true,330 +BenchmarkTest00490,weakrand,true,330 +BenchmarkTest00491,securecookie,true,614 +BenchmarkTest00492,xss,true,79 +BenchmarkTest00493,xss,false,79 +BenchmarkTest00494,cmdi,false,78 +BenchmarkTest00495,cmdi,true,78 +BenchmarkTest00496,cmdi,true,78 +BenchmarkTest00497,cmdi,true,78 +BenchmarkTest00498,cmdi,true,78 +BenchmarkTest00499,cmdi,true,78 +BenchmarkTest00500,cmdi,true,78 +BenchmarkTest00501,weakrand,false,330 +BenchmarkTest00502,weakrand,false,330 +BenchmarkTest00503,weakrand,false,330 +BenchmarkTest00504,weakrand,false,330 +BenchmarkTest00505,weakrand,false,330 +BenchmarkTest00506,weakrand,false,330 +BenchmarkTest00507,weakrand,false,330 +BenchmarkTest00508,trustbound,true,501 +BenchmarkTest00509,sqli,false,89 +BenchmarkTest00510,sqli,true,89 +BenchmarkTest00511,sqli,false,89 +BenchmarkTest00512,sqli,true,89 +BenchmarkTest00513,sqli,false,89 +BenchmarkTest00514,sqli,false,89 +BenchmarkTest00515,sqli,true,89 +BenchmarkTest00516,sqli,true,89 +BenchmarkTest00517,sqli,false,89 +BenchmarkTest00518,sqli,true,89 +BenchmarkTest00519,sqli,false,89 +BenchmarkTest00520,xpathi,false,643 +BenchmarkTest00521,crypto,true,327 +BenchmarkTest00522,crypto,true,327 +BenchmarkTest00523,crypto,false,327 +BenchmarkTest00524,crypto,false,327 +BenchmarkTest00525,pathtraver,true,22 +BenchmarkTest00526,pathtraver,true,22 +BenchmarkTest00527,pathtraver,true,22 +BenchmarkTest00528,pathtraver,true,22 +BenchmarkTest00529,pathtraver,true,22 +BenchmarkTest00530,ldapi,false,90 +BenchmarkTest00531,hash,true,328 +BenchmarkTest00532,hash,true,328 +BenchmarkTest00533,hash,true,328 +BenchmarkTest00534,hash,true,328 +BenchmarkTest00535,hash,false,328 +BenchmarkTest00536,hash,true,328 +BenchmarkTest00537,hash,true,328 +BenchmarkTest00538,hash,false,328 +BenchmarkTest00539,hash,false,328 +BenchmarkTest00540,hash,false,328 +BenchmarkTest00541,xss,true,79 +BenchmarkTest00542,xss,true,79 +BenchmarkTest00543,xss,true,79 +BenchmarkTest00544,xss,false,79 +BenchmarkTest00545,xss,false,79 +BenchmarkTest00546,xss,false,79 +BenchmarkTest00547,xss,true,79 +BenchmarkTest00548,xss,false,79 +BenchmarkTest00549,xss,true,79 +BenchmarkTest00550,xss,false,79 +BenchmarkTest00551,xss,true,79 +BenchmarkTest00552,xss,true,79 +BenchmarkTest00553,xss,false,79 +BenchmarkTest00554,xss,true,79 +BenchmarkTest00555,xss,true,79 +BenchmarkTest00556,xss,false,79 +BenchmarkTest00557,xss,true,79 +BenchmarkTest00558,cmdi,false,78 +BenchmarkTest00559,cmdi,false,78 +BenchmarkTest00560,weakrand,true,330 +BenchmarkTest00561,weakrand,true,330 +BenchmarkTest00562,weakrand,true,330 +BenchmarkTest00563,weakrand,true,330 +BenchmarkTest00564,weakrand,true,330 +BenchmarkTest00565,securecookie,true,614 +BenchmarkTest00566,securecookie,true,614 +BenchmarkTest00567,cmdi,true,78 +BenchmarkTest00568,cmdi,true,78 +BenchmarkTest00569,cmdi,false,78 +BenchmarkTest00570,cmdi,false,78 +BenchmarkTest00571,cmdi,false,78 +BenchmarkTest00572,cmdi,false,78 +BenchmarkTest00573,cmdi,true,78 +BenchmarkTest00574,cmdi,true,78 +BenchmarkTest00575,cmdi,true,78 +BenchmarkTest00576,cmdi,true,78 +BenchmarkTest00577,weakrand,false,330 +BenchmarkTest00578,weakrand,false,330 +BenchmarkTest00579,weakrand,false,330 +BenchmarkTest00580,weakrand,false,330 +BenchmarkTest00581,weakrand,false,330 +BenchmarkTest00582,weakrand,false,330 +BenchmarkTest00583,weakrand,false,330 +BenchmarkTest00584,weakrand,false,330 +BenchmarkTest00585,weakrand,false,330 +BenchmarkTest00586,trustbound,false,501 +BenchmarkTest00587,trustbound,true,501 +BenchmarkTest00588,trustbound,true,501 +BenchmarkTest00589,sqli,false,89 +BenchmarkTest00590,sqli,true,89 +BenchmarkTest00591,sqli,true,89 +BenchmarkTest00592,sqli,false,89 +BenchmarkTest00593,sqli,true,89 +BenchmarkTest00594,sqli,true,89 +BenchmarkTest00595,sqli,true,89 +BenchmarkTest00596,sqli,true,89 +BenchmarkTest00597,sqli,true,89 +BenchmarkTest00598,sqli,true,89 +BenchmarkTest00599,sqli,false,89 +BenchmarkTest00600,sqli,true,89 +BenchmarkTest00601,sqli,false,89 +BenchmarkTest00602,sqli,false,89 +BenchmarkTest00603,sqli,true,89 +BenchmarkTest00604,sqli,true,89 +BenchmarkTest00605,sqli,false,89 +BenchmarkTest00606,sqli,true,89 +BenchmarkTest00607,xpathi,true,643 +BenchmarkTest00608,crypto,true,327 +BenchmarkTest00609,crypto,true,327 +BenchmarkTest00610,crypto,true,327 +BenchmarkTest00611,crypto,true,327 +BenchmarkTest00612,crypto,false,327 +BenchmarkTest00613,crypto,false,327 +BenchmarkTest00614,crypto,true,327 +BenchmarkTest00615,crypto,true,327 +BenchmarkTest00616,crypto,true,327 +BenchmarkTest00617,crypto,true,327 +BenchmarkTest00618,crypto,false,327 +BenchmarkTest00619,pathtraver,true,22 +BenchmarkTest00620,pathtraver,false,22 +BenchmarkTest00621,pathtraver,false,22 +BenchmarkTest00622,pathtraver,false,22 +BenchmarkTest00623,pathtraver,true,22 +BenchmarkTest00624,pathtraver,true,22 +BenchmarkTest00625,pathtraver,false,22 +BenchmarkTest00626,pathtraver,false,22 +BenchmarkTest00627,pathtraver,true,22 +BenchmarkTest00628,pathtraver,false,22 +BenchmarkTest00629,pathtraver,true,22 +BenchmarkTest00630,ldapi,true,90 +BenchmarkTest00631,hash,true,328 +BenchmarkTest00632,hash,false,328 +BenchmarkTest00633,hash,false,328 +BenchmarkTest00634,hash,true,328 +BenchmarkTest00635,hash,true,328 +BenchmarkTest00636,hash,true,328 +BenchmarkTest00637,hash,true,328 +BenchmarkTest00638,hash,true,328 +BenchmarkTest00639,hash,false,328 +BenchmarkTest00640,hash,false,328 +BenchmarkTest00641,hash,false,328 +BenchmarkTest00642,xss,true,79 +BenchmarkTest00643,xss,true,79 +BenchmarkTest00644,xss,true,79 +BenchmarkTest00645,xss,true,79 +BenchmarkTest00646,xss,false,79 +BenchmarkTest00647,xss,false,79 +BenchmarkTest00648,xss,false,79 +BenchmarkTest00649,xss,false,79 +BenchmarkTest00650,xss,false,79 +BenchmarkTest00651,xss,true,79 +BenchmarkTest00652,weakrand,true,330 +BenchmarkTest00653,weakrand,true,330 +BenchmarkTest00654,weakrand,true,330 +BenchmarkTest00655,securecookie,false,614 +BenchmarkTest00656,xss,true,79 +BenchmarkTest00657,cmdi,false,78 +BenchmarkTest00658,cmdi,false,78 +BenchmarkTest00659,cmdi,false,78 +BenchmarkTest00660,weakrand,false,330 +BenchmarkTest00661,weakrand,false,330 +BenchmarkTest00662,weakrand,false,330 +BenchmarkTest00663,weakrand,false,330 +BenchmarkTest00664,weakrand,false,330 +BenchmarkTest00665,weakrand,false,330 +BenchmarkTest00666,weakrand,false,330 +BenchmarkTest00667,weakrand,false,330 +BenchmarkTest00668,trustbound,true,501 +BenchmarkTest00669,trustbound,false,501 +BenchmarkTest00670,trustbound,true,501 +BenchmarkTest00671,trustbound,true,501 +BenchmarkTest00672,sqli,false,89 +BenchmarkTest00673,sqli,true,89 +BenchmarkTest00674,sqli,false,89 +BenchmarkTest00675,sqli,false,89 +BenchmarkTest00676,sqli,false,89 +BenchmarkTest00677,sqli,true,89 +BenchmarkTest00678,sqli,true,89 +BenchmarkTest00679,sqli,true,89 +BenchmarkTest00680,sqli,false,89 +BenchmarkTest00681,sqli,true,89 +BenchmarkTest00682,sqli,false,89 +BenchmarkTest00683,xpathi,false,643 +BenchmarkTest00684,crypto,true,327 +BenchmarkTest00685,crypto,true,327 +BenchmarkTest00686,crypto,false,327 +BenchmarkTest00687,crypto,false,327 +BenchmarkTest00688,crypto,true,327 +BenchmarkTest00689,crypto,false,327 +BenchmarkTest00690,crypto,false,327 +BenchmarkTest00691,crypto,true,327 +BenchmarkTest00692,crypto,true,327 +BenchmarkTest00693,crypto,true,327 +BenchmarkTest00694,ldapi,true,90 +BenchmarkTest00695,ldapi,true,90 +BenchmarkTest00696,pathtraver,true,22 +BenchmarkTest00697,pathtraver,true,22 +BenchmarkTest00698,pathtraver,true,22 +BenchmarkTest00699,pathtraver,false,22 +BenchmarkTest00700,pathtraver,true,22 +BenchmarkTest00701,ldapi,false,90 +BenchmarkTest00702,weakrand,true,330 +BenchmarkTest00703,hash,true,328 +BenchmarkTest00704,hash,true,328 +BenchmarkTest00705,hash,true,328 +BenchmarkTest00706,hash,false,328 +BenchmarkTest00707,hash,false,328 +BenchmarkTest00708,hash,true,328 +BenchmarkTest00709,hash,false,328 +BenchmarkTest00710,hash,true,328 +BenchmarkTest00711,xss,true,79 +BenchmarkTest00712,xss,false,79 +BenchmarkTest00713,xss,false,79 +BenchmarkTest00714,xss,false,79 +BenchmarkTest00715,xss,true,79 +BenchmarkTest00716,xss,false,79 +BenchmarkTest00717,xss,false,79 +BenchmarkTest00718,xss,false,79 +BenchmarkTest00719,xss,true,79 +BenchmarkTest00720,xss,true,79 +BenchmarkTest00721,xss,true,79 +BenchmarkTest00722,xss,false,79 +BenchmarkTest00723,xss,false,79 +BenchmarkTest00724,xss,true,79 +BenchmarkTest00725,xss,true,79 +BenchmarkTest00726,xss,false,79 +BenchmarkTest00727,xss,true,79 +BenchmarkTest00728,xss,true,79 +BenchmarkTest00729,xss,true,79 +BenchmarkTest00730,xss,false,79 +BenchmarkTest00731,cmdi,true,78 +BenchmarkTest00732,cmdi,false,78 +BenchmarkTest00733,weakrand,true,330 +BenchmarkTest00734,weakrand,true,330 +BenchmarkTest00735,weakrand,true,330 +BenchmarkTest00736,securecookie,true,614 +BenchmarkTest00737,xss,true,79 +BenchmarkTest00738,cmdi,false,78 +BenchmarkTest00739,cmdi,false,78 +BenchmarkTest00740,cmdi,true,78 +BenchmarkTest00741,cmdi,false,78 +BenchmarkTest00742,cmdi,false,78 +BenchmarkTest00743,cmdi,false,78 +BenchmarkTest00744,weakrand,false,330 +BenchmarkTest00745,weakrand,false,330 +BenchmarkTest00746,weakrand,false,330 +BenchmarkTest00747,weakrand,false,330 +BenchmarkTest00748,weakrand,false,330 +BenchmarkTest00749,weakrand,false,330 +BenchmarkTest00750,weakrand,false,330 +BenchmarkTest00751,weakrand,false,330 +BenchmarkTest00752,weakrand,false,330 +BenchmarkTest00753,weakrand,false,330 +BenchmarkTest00754,trustbound,true,501 +BenchmarkTest00755,trustbound,false,501 +BenchmarkTest00756,trustbound,true,501 +BenchmarkTest00757,trustbound,true,501 +BenchmarkTest00758,trustbound,false,501 +BenchmarkTest00759,trustbound,true,501 +BenchmarkTest00760,sqli,true,89 +BenchmarkTest00761,sqli,true,89 +BenchmarkTest00762,sqli,true,89 +BenchmarkTest00763,sqli,false,89 +BenchmarkTest00764,sqli,true,89 +BenchmarkTest00765,sqli,true,89 +BenchmarkTest00766,sqli,false,89 +BenchmarkTest00767,sqli,true,89 +BenchmarkTest00768,sqli,true,89 +BenchmarkTest00769,sqli,true,89 +BenchmarkTest00770,sqli,true,89 +BenchmarkTest00771,sqli,true,89 +BenchmarkTest00772,sqli,false,89 +BenchmarkTest00773,sqli,false,89 +BenchmarkTest00774,sqli,false,89 +BenchmarkTest00775,crypto,false,327 +BenchmarkTest00776,crypto,false,327 +BenchmarkTest00777,crypto,false,327 +BenchmarkTest00778,crypto,false,327 +BenchmarkTest00779,crypto,true,327 +BenchmarkTest00780,crypto,false,327 +BenchmarkTest00781,crypto,true,327 +BenchmarkTest00782,crypto,false,327 +BenchmarkTest00783,pathtraver,true,22 +BenchmarkTest00784,pathtraver,false,22 +BenchmarkTest00785,pathtraver,true,22 +BenchmarkTest00786,pathtraver,false,22 +BenchmarkTest00787,pathtraver,true,22 +BenchmarkTest00788,pathtraver,true,22 +BenchmarkTest00789,hash,true,328 +BenchmarkTest00790,hash,true,328 +BenchmarkTest00791,hash,false,328 +BenchmarkTest00792,hash,false,328 +BenchmarkTest00793,hash,false,328 +BenchmarkTest00794,hash,true,328 +BenchmarkTest00795,hash,false,328 +BenchmarkTest00796,hash,true,328 +BenchmarkTest00797,hash,true,328 +BenchmarkTest00798,hash,false,328 +BenchmarkTest00799,xss,false,79 +BenchmarkTest00800,xss,true,79 +BenchmarkTest00801,xss,true,79 +BenchmarkTest00802,xss,true,79 +BenchmarkTest00803,xss,true,79 +BenchmarkTest00804,xss,true,79 +BenchmarkTest00805,xss,true,79 +BenchmarkTest00806,xss,true,79 +BenchmarkTest00807,xss,true,79 +BenchmarkTest00808,xss,false,79 +BenchmarkTest00809,xss,true,79 +BenchmarkTest00810,xss,true,79 +BenchmarkTest00811,xss,true,79 +BenchmarkTest00812,xss,false,79 +BenchmarkTest00813,xss,false,79 +BenchmarkTest00814,cmdi,false,78 +BenchmarkTest00815,cmdi,true,78 +BenchmarkTest00816,cmdi,true,78 +BenchmarkTest00817,weakrand,true,330 +BenchmarkTest00818,weakrand,true,330 +BenchmarkTest00819,weakrand,true,330 +BenchmarkTest00820,securecookie,true,614 +BenchmarkTest00821,securecookie,true,614 +BenchmarkTest00822,xss,true,79 +BenchmarkTest00823,cmdi,true,78 +BenchmarkTest00824,cmdi,true,78 +BenchmarkTest00825,cmdi,true,78 +BenchmarkTest00826,cmdi,false,78 +BenchmarkTest00827,cmdi,false,78 +BenchmarkTest00828,weakrand,false,330 +BenchmarkTest00829,weakrand,false,330 +BenchmarkTest00830,weakrand,false,330 +BenchmarkTest00831,weakrand,false,330 +BenchmarkTest00832,weakrand,false,330 +BenchmarkTest00833,trustbound,true,501 +BenchmarkTest00834,trustbound,true,501 +BenchmarkTest00835,trustbound,false,501 +BenchmarkTest00836,trustbound,true,501 +BenchmarkTest00837,sqli,false,89 +BenchmarkTest00838,sqli,false,89 +BenchmarkTest00839,sqli,true,89 +BenchmarkTest00840,sqli,true,89 +BenchmarkTest00841,sqli,true,89 +BenchmarkTest00842,sqli,true,89 +BenchmarkTest00843,sqli,true,89 +BenchmarkTest00844,sqli,false,89 +BenchmarkTest00845,sqli,true,89 +BenchmarkTest00846,sqli,true,89 +BenchmarkTest00847,sqli,true,89 +BenchmarkTest00848,sqli,true,89 +BenchmarkTest00849,sqli,true,89 +BenchmarkTest00850,sqli,true,89 +BenchmarkTest00851,sqli,false,89 +BenchmarkTest00852,xpathi,false,643 +BenchmarkTest00853,crypto,true,327 +BenchmarkTest00854,crypto,false,327 +BenchmarkTest00855,crypto,true,327 +BenchmarkTest00856,crypto,true,327 +BenchmarkTest00857,crypto,true,327 +BenchmarkTest00858,crypto,false,327 +BenchmarkTest00859,crypto,true,327 +BenchmarkTest00860,ldapi,false,90 +BenchmarkTest00861,ldapi,false,90 +BenchmarkTest00862,pathtraver,false,22 +BenchmarkTest00863,pathtraver,false,22 +BenchmarkTest00864,pathtraver,false,22 +BenchmarkTest00865,pathtraver,false,22 +BenchmarkTest00866,pathtraver,false,22 +BenchmarkTest00867,pathtraver,false,22 +BenchmarkTest00868,hash,true,328 +BenchmarkTest00869,hash,true,328 +BenchmarkTest00870,hash,true,328 +BenchmarkTest00871,hash,true,328 +BenchmarkTest00872,hash,true,328 +BenchmarkTest00873,hash,false,328 +BenchmarkTest00874,hash,false,328 +BenchmarkTest00875,hash,true,328 +BenchmarkTest00876,hash,true,328 +BenchmarkTest00877,hash,false,328 +BenchmarkTest00878,hash,false,328 +BenchmarkTest00879,xss,false,79 +BenchmarkTest00880,xss,false,79 +BenchmarkTest00881,xss,false,79 +BenchmarkTest00882,xss,false,79 +BenchmarkTest00883,xss,false,79 +BenchmarkTest00884,xss,false,79 +BenchmarkTest00885,xss,false,79 +BenchmarkTest00886,xss,false,79 +BenchmarkTest00887,xss,false,79 +BenchmarkTest00888,xss,false,79 +BenchmarkTest00889,xss,false,79 +BenchmarkTest00890,xss,false,79 +BenchmarkTest00891,xss,false,79 +BenchmarkTest00892,xss,false,79 +BenchmarkTest00893,xss,false,79 +BenchmarkTest00894,xss,false,79 +BenchmarkTest00895,cmdi,false,78 +BenchmarkTest00896,cmdi,false,78 +BenchmarkTest00897,cmdi,false,78 +BenchmarkTest00898,weakrand,true,330 +BenchmarkTest00899,weakrand,true,330 +BenchmarkTest00900,weakrand,true,330 +BenchmarkTest00901,weakrand,true,330 +BenchmarkTest00902,weakrand,true,330 +BenchmarkTest00903,securecookie,true,614 +BenchmarkTest00904,securecookie,false,614 +BenchmarkTest00905,cmdi,false,78 +BenchmarkTest00906,cmdi,false,78 +BenchmarkTest00907,cmdi,false,78 +BenchmarkTest00908,cmdi,false,78 +BenchmarkTest00909,cmdi,false,78 +BenchmarkTest00910,cmdi,false,78 +BenchmarkTest00911,weakrand,false,330 +BenchmarkTest00912,weakrand,false,330 +BenchmarkTest00913,weakrand,false,330 +BenchmarkTest00914,weakrand,false,330 +BenchmarkTest00915,weakrand,false,330 +BenchmarkTest00916,weakrand,false,330 +BenchmarkTest00917,weakrand,false,330 +BenchmarkTest00918,weakrand,false,330 +BenchmarkTest00919,weakrand,false,330 +BenchmarkTest00920,weakrand,false,330 +BenchmarkTest00921,weakrand,false,330 +BenchmarkTest00922,trustbound,false,501 +BenchmarkTest00923,trustbound,false,501 +BenchmarkTest00924,sqli,false,89 +BenchmarkTest00925,sqli,false,89 +BenchmarkTest00926,sqli,false,89 +BenchmarkTest00927,sqli,false,89 +BenchmarkTest00928,sqli,false,89 +BenchmarkTest00929,sqli,false,89 +BenchmarkTest00930,sqli,false,89 +BenchmarkTest00931,sqli,false,89 +BenchmarkTest00932,sqli,false,89 +BenchmarkTest00933,sqli,false,89 +BenchmarkTest00934,sqli,false,89 +BenchmarkTest00935,sqli,false,89 +BenchmarkTest00936,sqli,false,89 +BenchmarkTest00937,sqli,false,89 +BenchmarkTest00938,sqli,false,89 +BenchmarkTest00939,sqli,false,89 +BenchmarkTest00940,sqli,false,89 +BenchmarkTest00941,xpathi,false,643 +BenchmarkTest00942,crypto,false,327 +BenchmarkTest00943,crypto,false,327 +BenchmarkTest00944,crypto,false,327 +BenchmarkTest00945,crypto,true,327 +BenchmarkTest00946,crypto,true,327 +BenchmarkTest00947,ldapi,true,90 +BenchmarkTest00948,ldapi,false,90 +BenchmarkTest00949,pathtraver,true,22 +BenchmarkTest00950,pathtraver,true,22 +BenchmarkTest00951,pathtraver,false,22 +BenchmarkTest00952,pathtraver,true,22 +BenchmarkTest00953,pathtraver,true,22 +BenchmarkTest00954,pathtraver,false,22 +BenchmarkTest00955,pathtraver,false,22 +BenchmarkTest00956,pathtraver,true,22 +BenchmarkTest00957,pathtraver,false,22 +BenchmarkTest00958,pathtraver,false,22 +BenchmarkTest00959,ldapi,true,90 +BenchmarkTest00960,weakrand,true,330 +BenchmarkTest00961,hash,true,328 +BenchmarkTest00962,hash,false,328 +BenchmarkTest00963,hash,true,328 +BenchmarkTest00964,hash,false,328 +BenchmarkTest00965,hash,false,328 +BenchmarkTest00966,hash,false,328 +BenchmarkTest00967,hash,false,328 +BenchmarkTest00968,cmdi,true,78 +BenchmarkTest00969,cmdi,false,78 +BenchmarkTest00970,cmdi,false,78 +BenchmarkTest00971,weakrand,true,330 +BenchmarkTest00972,weakrand,true,330 +BenchmarkTest00973,weakrand,true,330 +BenchmarkTest00974,weakrand,true,330 +BenchmarkTest00975,weakrand,true,330 +BenchmarkTest00976,weakrand,true,330 +BenchmarkTest00977,securecookie,true,614 +BenchmarkTest00978,cmdi,false,78 +BenchmarkTest00979,cmdi,true,78 +BenchmarkTest00980,cmdi,false,78 +BenchmarkTest00981,cmdi,true,78 +BenchmarkTest00982,cmdi,false,78 +BenchmarkTest00983,cmdi,true,78 +BenchmarkTest00984,weakrand,false,330 +BenchmarkTest00985,weakrand,false,330 +BenchmarkTest00986,weakrand,false,330 +BenchmarkTest00987,weakrand,false,330 +BenchmarkTest00988,weakrand,false,330 +BenchmarkTest00989,weakrand,false,330 +BenchmarkTest00990,weakrand,false,330 +BenchmarkTest00991,trustbound,true,501 +BenchmarkTest00992,trustbound,false,501 +BenchmarkTest00993,trustbound,false,501 +BenchmarkTest00994,trustbound,true,501 +BenchmarkTest00995,trustbound,true,501 +BenchmarkTest00996,sqli,true,89 +BenchmarkTest00997,sqli,true,89 +BenchmarkTest00998,sqli,true,89 +BenchmarkTest00999,sqli,false,89 +BenchmarkTest01000,sqli,true,89 +BenchmarkTest01001,sqli,false,89 +BenchmarkTest01002,sqli,true,89 +BenchmarkTest01003,sqli,true,89 +BenchmarkTest01004,sqli,true,89 +BenchmarkTest01005,sqli,true,89 +BenchmarkTest01006,sqli,true,89 +BenchmarkTest01007,sqli,true,89 +BenchmarkTest01008,sqli,true,89 +BenchmarkTest01009,sqli,true,89 +BenchmarkTest01010,sqli,false,89 +BenchmarkTest01011,sqli,true,89 +BenchmarkTest01012,sqli,false,89 +BenchmarkTest01013,xpathi,false,643 +BenchmarkTest01014,xpathi,false,643 +BenchmarkTest01015,crypto,true,327 +BenchmarkTest01016,crypto,true,327 +BenchmarkTest01017,crypto,true,327 +BenchmarkTest01018,crypto,true,327 +BenchmarkTest01019,crypto,false,327 +BenchmarkTest01020,crypto,true,327 +BenchmarkTest01021,crypto,false,327 +BenchmarkTest01022,crypto,false,327 +BenchmarkTest01023,ldapi,true,90 +BenchmarkTest01024,ldapi,false,90 +BenchmarkTest01025,pathtraver,true,22 +BenchmarkTest01026,pathtraver,false,22 +BenchmarkTest01027,pathtraver,false,22 +BenchmarkTest01028,pathtraver,false,22 +BenchmarkTest01029,pathtraver,true,22 +BenchmarkTest01030,pathtraver,false,22 +BenchmarkTest01031,pathtraver,false,22 +BenchmarkTest01032,pathtraver,true,22 +BenchmarkTest01033,pathtraver,true,22 +BenchmarkTest01034,pathtraver,true,22 +BenchmarkTest01035,pathtraver,false,22 +BenchmarkTest01036,pathtraver,false,22 +BenchmarkTest01037,hash,false,328 +BenchmarkTest01038,hash,true,328 +BenchmarkTest01039,hash,false,328 +BenchmarkTest01040,hash,false,328 +BenchmarkTest01041,hash,true,328 +BenchmarkTest01042,hash,true,328 +BenchmarkTest01043,hash,true,328 +BenchmarkTest01044,hash,true,328 +BenchmarkTest01045,hash,false,328 +BenchmarkTest01046,xss,true,79 +BenchmarkTest01047,xss,true,79 +BenchmarkTest01048,xss,false,79 +BenchmarkTest01049,xss,true,79 +BenchmarkTest01050,xss,true,79 +BenchmarkTest01051,xss,false,79 +BenchmarkTest01052,xss,false,79 +BenchmarkTest01053,xss,false,79 +BenchmarkTest01054,xss,false,79 +BenchmarkTest01055,xss,true,79 +BenchmarkTest01056,xss,true,79 +BenchmarkTest01057,xss,true,79 +BenchmarkTest01058,weakrand,true,330 +BenchmarkTest01059,weakrand,true,330 +BenchmarkTest01060,weakrand,true,330 +BenchmarkTest01061,securecookie,true,614 +BenchmarkTest01062,securecookie,false,614 +BenchmarkTest01063,xss,true,79 +BenchmarkTest01064,cmdi,true,78 +BenchmarkTest01065,cmdi,false,78 +BenchmarkTest01066,cmdi,true,78 +BenchmarkTest01067,cmdi,false,78 +BenchmarkTest01068,cmdi,false,78 +BenchmarkTest01069,weakrand,false,330 +BenchmarkTest01070,weakrand,false,330 +BenchmarkTest01071,weakrand,false,330 +BenchmarkTest01072,weakrand,false,330 +BenchmarkTest01073,weakrand,false,330 +BenchmarkTest01074,weakrand,false,330 +BenchmarkTest01075,weakrand,false,330 +BenchmarkTest01076,weakrand,false,330 +BenchmarkTest01077,weakrand,false,330 +BenchmarkTest01078,weakrand,false,330 +BenchmarkTest01079,weakrand,false,330 +BenchmarkTest01080,trustbound,false,501 +BenchmarkTest01081,trustbound,true,501 +BenchmarkTest01082,trustbound,true,501 +BenchmarkTest01083,sqli,true,89 +BenchmarkTest01084,sqli,true,89 +BenchmarkTest01085,sqli,false,89 +BenchmarkTest01086,sqli,false,89 +BenchmarkTest01087,sqli,true,89 +BenchmarkTest01088,sqli,true,89 +BenchmarkTest01089,sqli,false,89 +BenchmarkTest01090,sqli,true,89 +BenchmarkTest01091,sqli,true,89 +BenchmarkTest01092,sqli,false,89 +BenchmarkTest01093,sqli,true,89 +BenchmarkTest01094,sqli,true,89 +BenchmarkTest01095,sqli,false,89 +BenchmarkTest01096,sqli,false,89 +BenchmarkTest01097,sqli,true,89 +BenchmarkTest01098,sqli,false,89 +BenchmarkTest01099,crypto,true,327 +BenchmarkTest01100,crypto,false,327 +BenchmarkTest01101,crypto,false,327 +BenchmarkTest01102,crypto,true,327 +BenchmarkTest01103,crypto,true,327 +BenchmarkTest01104,crypto,false,327 +BenchmarkTest01105,crypto,true,327 +BenchmarkTest01106,crypto,true,327 +BenchmarkTest01107,crypto,true,327 +BenchmarkTest01108,crypto,false,327 +BenchmarkTest01109,pathtraver,false,22 +BenchmarkTest01110,pathtraver,false,22 +BenchmarkTest01111,pathtraver,true,22 +BenchmarkTest01112,pathtraver,true,22 +BenchmarkTest01113,pathtraver,false,22 +BenchmarkTest01114,pathtraver,false,22 +BenchmarkTest01115,pathtraver,false,22 +BenchmarkTest01116,pathtraver,true,22 +BenchmarkTest01117,pathtraver,true,22 +BenchmarkTest01118,pathtraver,false,22 +BenchmarkTest01119,weakrand,true,330 +BenchmarkTest01120,hash,false,328 +BenchmarkTest01121,hash,false,328 +BenchmarkTest01122,hash,false,328 +BenchmarkTest01123,hash,true,328 +BenchmarkTest01124,hash,true,328 +BenchmarkTest01125,hash,false,328 +BenchmarkTest01126,hash,false,328 +BenchmarkTest01127,weakrand,true,330 +BenchmarkTest01128,weakrand,true,330 +BenchmarkTest01129,weakrand,true,330 +BenchmarkTest01130,weakrand,true,330 +BenchmarkTest01131,weakrand,true,330 +BenchmarkTest01132,weakrand,true,330 +BenchmarkTest01133,weakrand,true,330 +BenchmarkTest01134,securecookie,true,614 +BenchmarkTest01135,weakrand,false,330 +BenchmarkTest01136,weakrand,false,330 +BenchmarkTest01137,weakrand,false,330 +BenchmarkTest01138,weakrand,false,330 +BenchmarkTest01139,weakrand,false,330 +BenchmarkTest01140,weakrand,false,330 +BenchmarkTest01141,weakrand,false,330 +BenchmarkTest01142,trustbound,false,501 +BenchmarkTest01143,trustbound,true,501 +BenchmarkTest01144,trustbound,false,501 +BenchmarkTest01145,trustbound,false,501 +BenchmarkTest01146,trustbound,false,501 +BenchmarkTest01147,crypto,false,327 +BenchmarkTest01148,crypto,true,327 +BenchmarkTest01149,crypto,true,327 +BenchmarkTest01150,crypto,true,327 +BenchmarkTest01151,crypto,false,327 +BenchmarkTest01152,crypto,false,327 +BenchmarkTest01153,crypto,false,327 +BenchmarkTest01154,ldapi,false,90 +BenchmarkTest01155,pathtraver,true,22 +BenchmarkTest01156,pathtraver,true,22 +BenchmarkTest01157,pathtraver,true,22 +BenchmarkTest01158,pathtraver,false,22 +BenchmarkTest01159,pathtraver,false,22 +BenchmarkTest01160,pathtraver,false,22 +BenchmarkTest01161,pathtraver,true,22 +BenchmarkTest01162,weakrand,true,330 +BenchmarkTest01163,weakrand,true,330 +BenchmarkTest01164,hash,false,328 +BenchmarkTest01165,hash,true,328 +BenchmarkTest01166,hash,true,328 +BenchmarkTest01167,hash,true,328 +BenchmarkTest01168,hash,true,328 +BenchmarkTest01169,hash,false,328 +BenchmarkTest01170,hash,false,328 +BenchmarkTest01171,xss,true,79 +BenchmarkTest01172,xss,true,79 +BenchmarkTest01173,xss,true,79 +BenchmarkTest01174,xss,true,79 +BenchmarkTest01175,xss,false,79 +BenchmarkTest01176,xss,false,79 +BenchmarkTest01177,xss,true,79 +BenchmarkTest01178,xss,true,79 +BenchmarkTest01179,xss,true,79 +BenchmarkTest01180,xss,false,79 +BenchmarkTest01181,xss,true,79 +BenchmarkTest01182,cmdi,false,78 +BenchmarkTest01183,weakrand,true,330 +BenchmarkTest01184,weakrand,true,330 +BenchmarkTest01185,securecookie,true,614 +BenchmarkTest01186,securecookie,true,614 +BenchmarkTest01187,securecookie,true,614 +BenchmarkTest01188,xss,false,79 +BenchmarkTest01189,cmdi,false,78 +BenchmarkTest01190,cmdi,true,78 +BenchmarkTest01191,cmdi,true,78 +BenchmarkTest01192,cmdi,true,78 +BenchmarkTest01193,cmdi,false,78 +BenchmarkTest01194,cmdi,true,78 +BenchmarkTest01195,weakrand,false,330 +BenchmarkTest01196,weakrand,false,330 +BenchmarkTest01197,weakrand,false,330 +BenchmarkTest01198,weakrand,false,330 +BenchmarkTest01199,weakrand,false,330 +BenchmarkTest01200,weakrand,false,330 +BenchmarkTest01201,weakrand,false,330 +BenchmarkTest01202,weakrand,false,330 +BenchmarkTest01203,trustbound,true,501 +BenchmarkTest01204,trustbound,true,501 +BenchmarkTest01205,trustbound,false,501 +BenchmarkTest01206,trustbound,true,501 +BenchmarkTest01207,trustbound,false,501 +BenchmarkTest01208,sqli,true,89 +BenchmarkTest01209,sqli,true,89 +BenchmarkTest01210,sqli,true,89 +BenchmarkTest01211,sqli,true,89 +BenchmarkTest01212,sqli,false,89 +BenchmarkTest01213,sqli,false,89 +BenchmarkTest01214,sqli,true,89 +BenchmarkTest01215,sqli,false,89 +BenchmarkTest01216,sqli,false,89 +BenchmarkTest01217,sqli,false,89 +BenchmarkTest01218,sqli,false,89 +BenchmarkTest01219,sqli,false,89 +BenchmarkTest01220,sqli,false,89 +BenchmarkTest01221,sqli,true,89 +BenchmarkTest01222,sqli,true,89 +BenchmarkTest01223,xpathi,true,643 +BenchmarkTest01224,xpathi,true,643 +BenchmarkTest01225,xpathi,false,643 +BenchmarkTest01226,crypto,false,327 +BenchmarkTest01227,crypto,false,327 +BenchmarkTest01228,crypto,true,327 +BenchmarkTest01229,crypto,true,327 +BenchmarkTest01230,crypto,true,327 +BenchmarkTest01231,pathtraver,true,22 +BenchmarkTest01232,pathtraver,true,22 +BenchmarkTest01233,pathtraver,false,22 +BenchmarkTest01234,pathtraver,true,22 +BenchmarkTest01235,pathtraver,true,22 +BenchmarkTest01236,pathtraver,true,22 +BenchmarkTest01237,pathtraver,false,22 +BenchmarkTest01238,pathtraver,true,22 +BenchmarkTest01239,pathtraver,false,22 +BenchmarkTest01240,pathtraver,false,22 +BenchmarkTest01241,ldapi,true,90 +BenchmarkTest01242,ldapi,true,90 +BenchmarkTest01243,ldapi,true,90 +BenchmarkTest01244,hash,true,328 +BenchmarkTest01245,hash,false,328 +BenchmarkTest01246,hash,true,328 +BenchmarkTest01247,hash,true,328 +BenchmarkTest01248,hash,true,328 +BenchmarkTest01249,hash,false,328 +BenchmarkTest01250,hash,false,328 +BenchmarkTest01251,xss,false,79 +BenchmarkTest01252,xss,false,79 +BenchmarkTest01253,xss,true,79 +BenchmarkTest01254,xss,true,79 +BenchmarkTest01255,xss,false,79 +BenchmarkTest01256,xss,false,79 +BenchmarkTest01257,xss,true,79 +BenchmarkTest01258,xss,true,79 +BenchmarkTest01259,xss,true,79 +BenchmarkTest01260,xss,true,79 +BenchmarkTest01261,xss,true,79 +BenchmarkTest01262,xss,true,79 +BenchmarkTest01263,xss,true,79 +BenchmarkTest01264,xss,false,79 +BenchmarkTest01265,xss,false,79 +BenchmarkTest01266,xss,true,79 +BenchmarkTest01267,xss,true,79 +BenchmarkTest01268,xss,true,79 +BenchmarkTest01269,cmdi,false,78 +BenchmarkTest01270,cmdi,true,78 +BenchmarkTest01271,weakrand,true,330 +BenchmarkTest01272,weakrand,true,330 +BenchmarkTest01273,weakrand,true,330 +BenchmarkTest01274,weakrand,true,330 +BenchmarkTest01275,weakrand,true,330 +BenchmarkTest01276,weakrand,true,330 +BenchmarkTest01277,weakrand,true,330 +BenchmarkTest01278,weakrand,true,330 +BenchmarkTest01279,weakrand,true,330 +BenchmarkTest01280,securecookie,true,614 +BenchmarkTest01281,securecookie,true,614 +BenchmarkTest01282,securecookie,true,614 +BenchmarkTest01283,securecookie,true,614 +BenchmarkTest01284,xss,true,79 +BenchmarkTest01285,cmdi,true,78 +BenchmarkTest01286,cmdi,true,78 +BenchmarkTest01287,cmdi,true,78 +BenchmarkTest01288,cmdi,true,78 +BenchmarkTest01289,cmdi,false,78 +BenchmarkTest01290,cmdi,false,78 +BenchmarkTest01291,weakrand,false,330 +BenchmarkTest01292,weakrand,false,330 +BenchmarkTest01293,weakrand,false,330 +BenchmarkTest01294,weakrand,false,330 +BenchmarkTest01295,weakrand,false,330 +BenchmarkTest01296,weakrand,false,330 +BenchmarkTest01297,weakrand,false,330 +BenchmarkTest01298,weakrand,false,330 +BenchmarkTest01299,trustbound,true,501 +BenchmarkTest01300,trustbound,false,501 +BenchmarkTest01301,sqli,false,89 +BenchmarkTest01302,sqli,true,89 +BenchmarkTest01303,sqli,false,89 +BenchmarkTest01304,sqli,true,89 +BenchmarkTest01305,sqli,false,89 +BenchmarkTest01306,sqli,true,89 +BenchmarkTest01307,sqli,false,89 +BenchmarkTest01308,sqli,true,89 +BenchmarkTest01309,sqli,false,89 +BenchmarkTest01310,sqli,false,89 +BenchmarkTest01311,sqli,true,89 +BenchmarkTest01312,sqli,true,89 +BenchmarkTest01313,sqli,true,89 +BenchmarkTest01314,sqli,true,89 +BenchmarkTest01315,sqli,false,89 +BenchmarkTest01316,xpathi,true,643 +BenchmarkTest01317,crypto,true,327 +BenchmarkTest01318,crypto,true,327 +BenchmarkTest01319,crypto,false,327 +BenchmarkTest01320,crypto,true,327 +BenchmarkTest01321,crypto,false,327 +BenchmarkTest01322,crypto,true,327 +BenchmarkTest01323,crypto,true,327 +BenchmarkTest01324,crypto,false,327 +BenchmarkTest01325,crypto,true,327 +BenchmarkTest01326,ldapi,true,90 +BenchmarkTest01327,ldapi,false,90 +BenchmarkTest01328,pathtraver,false,22 +BenchmarkTest01329,pathtraver,true,22 +BenchmarkTest01330,pathtraver,true,22 +BenchmarkTest01331,pathtraver,false,22 +BenchmarkTest01332,hash,false,328 +BenchmarkTest01333,hash,true,328 +BenchmarkTest01334,hash,true,328 +BenchmarkTest01335,xss,true,79 +BenchmarkTest01336,xss,false,79 +BenchmarkTest01337,xss,true,79 +BenchmarkTest01338,xss,false,79 +BenchmarkTest01339,xss,false,79 +BenchmarkTest01340,xss,false,79 +BenchmarkTest01341,xss,false,79 +BenchmarkTest01342,xss,false,79 +BenchmarkTest01343,xss,false,79 +BenchmarkTest01344,xss,false,79 +BenchmarkTest01345,xss,false,79 +BenchmarkTest01346,xss,true,79 +BenchmarkTest01347,xss,true,79 +BenchmarkTest01348,xss,false,79 +BenchmarkTest01349,xss,true,79 +BenchmarkTest01350,xss,true,79 +BenchmarkTest01351,xss,false,79 +BenchmarkTest01352,xss,false,79 +BenchmarkTest01353,cmdi,false,78 +BenchmarkTest01354,weakrand,true,330 +BenchmarkTest01355,weakrand,true,330 +BenchmarkTest01356,weakrand,true,330 +BenchmarkTest01357,weakrand,true,330 +BenchmarkTest01358,weakrand,true,330 +BenchmarkTest01359,securecookie,false,614 +BenchmarkTest01360,cmdi,true,78 +BenchmarkTest01361,cmdi,true,78 +BenchmarkTest01362,cmdi,true,78 +BenchmarkTest01363,cmdi,true,78 +BenchmarkTest01364,cmdi,false,78 +BenchmarkTest01365,cmdi,false,78 +BenchmarkTest01366,weakrand,false,330 +BenchmarkTest01367,weakrand,false,330 +BenchmarkTest01368,weakrand,false,330 +BenchmarkTest01369,weakrand,false,330 +BenchmarkTest01370,weakrand,false,330 +BenchmarkTest01371,weakrand,false,330 +BenchmarkTest01372,weakrand,false,330 +BenchmarkTest01373,weakrand,false,330 +BenchmarkTest01374,trustbound,true,501 +BenchmarkTest01375,trustbound,true,501 +BenchmarkTest01376,trustbound,true,501 +BenchmarkTest01377,trustbound,false,501 +BenchmarkTest01378,sqli,false,89 +BenchmarkTest01379,sqli,true,89 +BenchmarkTest01380,sqli,false,89 +BenchmarkTest01381,sqli,true,89 +BenchmarkTest01382,sqli,true,89 +BenchmarkTest01383,sqli,true,89 +BenchmarkTest01384,sqli,true,89 +BenchmarkTest01385,sqli,false,89 +BenchmarkTest01386,sqli,false,89 +BenchmarkTest01387,sqli,false,89 +BenchmarkTest01388,sqli,true,89 +BenchmarkTest01389,sqli,false,89 +BenchmarkTest01390,sqli,true,89 +BenchmarkTest01391,sqli,true,89 +BenchmarkTest01392,sqli,false,89 +BenchmarkTest01393,sqli,false,89 +BenchmarkTest01394,sqli,true,89 +BenchmarkTest01395,sqli,true,89 +BenchmarkTest01396,sqli,true,89 +BenchmarkTest01397,xpathi,false,643 +BenchmarkTest01398,crypto,true,327 +BenchmarkTest01399,crypto,false,327 +BenchmarkTest01400,crypto,false,327 +BenchmarkTest01401,crypto,false,327 +BenchmarkTest01402,ldapi,false,90 +BenchmarkTest01403,pathtraver,true,22 +BenchmarkTest01404,pathtraver,false,22 +BenchmarkTest01405,pathtraver,true,22 +BenchmarkTest01406,pathtraver,false,22 +BenchmarkTest01407,pathtraver,false,22 +BenchmarkTest01408,pathtraver,true,22 +BenchmarkTest01409,pathtraver,false,22 +BenchmarkTest01410,hash,false,328 +BenchmarkTest01411,hash,true,328 +BenchmarkTest01412,hash,false,328 +BenchmarkTest01413,hash,false,328 +BenchmarkTest01414,hash,true,328 +BenchmarkTest01415,hash,true,328 +BenchmarkTest01416,hash,true,328 +BenchmarkTest01417,xss,true,79 +BenchmarkTest01418,xss,true,79 +BenchmarkTest01419,xss,false,79 +BenchmarkTest01420,xss,false,79 +BenchmarkTest01421,xss,false,79 +BenchmarkTest01422,xss,false,79 +BenchmarkTest01423,xss,true,79 +BenchmarkTest01424,xss,true,79 +BenchmarkTest01425,xss,false,79 +BenchmarkTest01426,xss,true,79 +BenchmarkTest01427,xss,true,79 +BenchmarkTest01428,xss,true,79 +BenchmarkTest01429,xss,true,79 +BenchmarkTest01430,cmdi,true,78 +BenchmarkTest01431,weakrand,true,330 +BenchmarkTest01432,weakrand,true,330 +BenchmarkTest01433,weakrand,true,330 +BenchmarkTest01434,weakrand,true,330 +BenchmarkTest01435,weakrand,true,330 +BenchmarkTest01436,securecookie,false,614 +BenchmarkTest01437,xss,true,79 +BenchmarkTest01438,xss,true,79 +BenchmarkTest01439,xss,false,79 +BenchmarkTest01440,cmdi,false,78 +BenchmarkTest01441,cmdi,true,78 +BenchmarkTest01442,cmdi,true,78 +BenchmarkTest01443,cmdi,false,78 +BenchmarkTest01444,cmdi,false,78 +BenchmarkTest01445,cmdi,false,78 +BenchmarkTest01446,cmdi,true,78 +BenchmarkTest01447,weakrand,false,330 +BenchmarkTest01448,weakrand,false,330 +BenchmarkTest01449,weakrand,false,330 +BenchmarkTest01450,weakrand,false,330 +BenchmarkTest01451,weakrand,false,330 +BenchmarkTest01452,weakrand,false,330 +BenchmarkTest01453,weakrand,false,330 +BenchmarkTest01454,trustbound,false,501 +BenchmarkTest01455,trustbound,true,501 +BenchmarkTest01456,trustbound,true,501 +BenchmarkTest01457,trustbound,true,501 +BenchmarkTest01458,trustbound,true,501 +BenchmarkTest01459,sqli,false,89 +BenchmarkTest01460,sqli,true,89 +BenchmarkTest01461,sqli,false,89 +BenchmarkTest01462,sqli,true,89 +BenchmarkTest01463,sqli,true,89 +BenchmarkTest01464,sqli,true,89 +BenchmarkTest01465,sqli,true,89 +BenchmarkTest01466,sqli,true,89 +BenchmarkTest01467,sqli,false,89 +BenchmarkTest01468,sqli,false,89 +BenchmarkTest01469,sqli,false,89 +BenchmarkTest01470,sqli,true,89 +BenchmarkTest01471,sqli,true,89 +BenchmarkTest01472,sqli,false,89 +BenchmarkTest01473,sqli,true,89 +BenchmarkTest01474,sqli,true,89 +BenchmarkTest01475,sqli,true,89 +BenchmarkTest01476,sqli,true,89 +BenchmarkTest01477,sqli,true,89 +BenchmarkTest01478,xpathi,true,643 +BenchmarkTest01479,xpathi,false,643 +BenchmarkTest01480,crypto,true,327 +BenchmarkTest01481,crypto,false,327 +BenchmarkTest01482,crypto,false,327 +BenchmarkTest01483,crypto,true,327 +BenchmarkTest01484,crypto,true,327 +BenchmarkTest01485,crypto,false,327 +BenchmarkTest01486,crypto,true,327 +BenchmarkTest01487,crypto,false,327 +BenchmarkTest01488,crypto,false,327 +BenchmarkTest01489,crypto,true,327 +BenchmarkTest01490,ldapi,true,90 +BenchmarkTest01491,ldapi,false,90 +BenchmarkTest01492,ldapi,false,90 +BenchmarkTest01493,pathtraver,false,22 +BenchmarkTest01494,pathtraver,true,22 +BenchmarkTest01495,pathtraver,true,22 +BenchmarkTest01496,pathtraver,true,22 +BenchmarkTest01497,pathtraver,true,22 +BenchmarkTest01498,pathtraver,true,22 +BenchmarkTest01499,pathtraver,false,22 +BenchmarkTest01500,pathtraver,true,22 +BenchmarkTest01501,ldapi,true,90 +BenchmarkTest01502,weakrand,true,330 +BenchmarkTest01503,hash,true,328 +BenchmarkTest01504,hash,true,328 +BenchmarkTest01505,xss,true,79 +BenchmarkTest01506,xss,true,79 +BenchmarkTest01507,xss,true,79 +BenchmarkTest01508,xss,false,79 +BenchmarkTest01509,xss,true,79 +BenchmarkTest01510,xss,true,79 +BenchmarkTest01511,xss,true,79 +BenchmarkTest01512,xss,true,79 +BenchmarkTest01513,xss,false,79 +BenchmarkTest01514,xss,false,79 +BenchmarkTest01515,xss,false,79 +BenchmarkTest01516,cmdi,false,78 +BenchmarkTest01517,cmdi,true,78 +BenchmarkTest01518,weakrand,true,330 +BenchmarkTest01519,weakrand,true,330 +BenchmarkTest01520,weakrand,true,330 +BenchmarkTest01521,securecookie,true,614 +BenchmarkTest01522,securecookie,false,614 +BenchmarkTest01523,securecookie,false,614 +BenchmarkTest01524,securecookie,false,614 +BenchmarkTest01525,xss,true,79 +BenchmarkTest01526,cmdi,false,78 +BenchmarkTest01527,cmdi,false,78 +BenchmarkTest01528,cmdi,false,78 +BenchmarkTest01529,cmdi,false,78 +BenchmarkTest01530,cmdi,false,78 +BenchmarkTest01531,cmdi,true,78 +BenchmarkTest01532,cmdi,false,78 +BenchmarkTest01533,cmdi,true,78 +BenchmarkTest01534,weakrand,false,330 +BenchmarkTest01535,weakrand,false,330 +BenchmarkTest01536,weakrand,false,330 +BenchmarkTest01537,weakrand,false,330 +BenchmarkTest01538,weakrand,false,330 +BenchmarkTest01539,weakrand,false,330 +BenchmarkTest01540,weakrand,false,330 +BenchmarkTest01541,weakrand,false,330 +BenchmarkTest01542,weakrand,false,330 +BenchmarkTest01543,weakrand,false,330 +BenchmarkTest01544,weakrand,false,330 +BenchmarkTest01545,weakrand,false,330 +BenchmarkTest01546,trustbound,true,501 +BenchmarkTest01547,trustbound,true,501 +BenchmarkTest01548,trustbound,true,501 +BenchmarkTest01549,trustbound,true,501 +BenchmarkTest01550,trustbound,true,501 +BenchmarkTest01551,trustbound,true,501 +BenchmarkTest01552,sqli,true,89 +BenchmarkTest01553,sqli,false,89 +BenchmarkTest01554,sqli,true,89 +BenchmarkTest01555,sqli,false,89 +BenchmarkTest01556,sqli,false,89 +BenchmarkTest01557,sqli,true,89 +BenchmarkTest01558,sqli,true,89 +BenchmarkTest01559,sqli,true,89 +BenchmarkTest01560,sqli,true,89 +BenchmarkTest01561,xpathi,true,643 +BenchmarkTest01562,xpathi,false,643 +BenchmarkTest01563,crypto,false,327 +BenchmarkTest01564,crypto,false,327 +BenchmarkTest01565,crypto,true,327 +BenchmarkTest01566,crypto,true,327 +BenchmarkTest01567,crypto,false,327 +BenchmarkTest01568,ldapi,true,90 +BenchmarkTest01569,ldapi,false,90 +BenchmarkTest01570,pathtraver,false,22 +BenchmarkTest01571,pathtraver,true,22 +BenchmarkTest01572,pathtraver,true,22 +BenchmarkTest01573,pathtraver,false,22 +BenchmarkTest01574,pathtraver,false,22 +BenchmarkTest01575,weakrand,true,330 +BenchmarkTest01576,hash,false,328 +BenchmarkTest01577,hash,true,328 +BenchmarkTest01578,hash,false,328 +BenchmarkTest01579,hash,true,328 +BenchmarkTest01580,hash,true,328 +BenchmarkTest01581,hash,false,328 +BenchmarkTest01582,hash,false,328 +BenchmarkTest01583,xss,true,79 +BenchmarkTest01584,xss,true,79 +BenchmarkTest01585,xss,false,79 +BenchmarkTest01586,xss,false,79 +BenchmarkTest01587,xss,true,79 +BenchmarkTest01588,xss,false,79 +BenchmarkTest01589,xss,true,79 +BenchmarkTest01590,xss,true,79 +BenchmarkTest01591,xss,false,79 +BenchmarkTest01592,xss,true,79 +BenchmarkTest01593,xss,false,79 +BenchmarkTest01594,xss,true,79 +BenchmarkTest01595,xss,false,79 +BenchmarkTest01596,xss,true,79 +BenchmarkTest01597,xss,true,79 +BenchmarkTest01598,xss,true,79 +BenchmarkTest01599,xss,false,79 +BenchmarkTest01600,cmdi,false,78 +BenchmarkTest01601,cmdi,true,78 +BenchmarkTest01602,weakrand,true,330 +BenchmarkTest01603,weakrand,true,330 +BenchmarkTest01604,securecookie,false,614 +BenchmarkTest01605,securecookie,false,614 +BenchmarkTest01606,cmdi,false,78 +BenchmarkTest01607,cmdi,false,78 +BenchmarkTest01608,cmdi,false,78 +BenchmarkTest01609,cmdi,true,78 +BenchmarkTest01610,cmdi,true,78 +BenchmarkTest01611,weakrand,false,330 +BenchmarkTest01612,weakrand,false,330 +BenchmarkTest01613,weakrand,false,330 +BenchmarkTest01614,weakrand,false,330 +BenchmarkTest01615,trustbound,true,501 +BenchmarkTest01616,trustbound,true,501 +BenchmarkTest01617,trustbound,true,501 +BenchmarkTest01618,trustbound,true,501 +BenchmarkTest01619,trustbound,true,501 +BenchmarkTest01620,sqli,true,89 +BenchmarkTest01621,sqli,true,89 +BenchmarkTest01622,sqli,false,89 +BenchmarkTest01623,sqli,true,89 +BenchmarkTest01624,sqli,true,89 +BenchmarkTest01625,sqli,true,89 +BenchmarkTest01626,sqli,true,89 +BenchmarkTest01627,sqli,true,89 +BenchmarkTest01628,sqli,false,89 +BenchmarkTest01629,sqli,false,89 +BenchmarkTest01630,sqli,true,89 +BenchmarkTest01631,sqli,true,89 +BenchmarkTest01632,xpathi,false,643 +BenchmarkTest01633,xpathi,false,643 +BenchmarkTest01634,crypto,true,327 +BenchmarkTest01635,crypto,false,327 +BenchmarkTest01636,crypto,false,327 +BenchmarkTest01637,crypto,true,327 +BenchmarkTest01638,crypto,true,327 +BenchmarkTest01639,crypto,true,327 +BenchmarkTest01640,crypto,false,327 +BenchmarkTest01641,crypto,true,327 +BenchmarkTest01642,pathtraver,true,22 +BenchmarkTest01643,pathtraver,true,22 +BenchmarkTest01644,pathtraver,false,22 +BenchmarkTest01645,pathtraver,true,22 +BenchmarkTest01646,pathtraver,false,22 +BenchmarkTest01647,pathtraver,true,22 +BenchmarkTest01648,weakrand,true,330 +BenchmarkTest01649,hash,true,328 +BenchmarkTest01650,hash,true,328 +BenchmarkTest01651,hash,true,328 +BenchmarkTest01652,hash,false,328 +BenchmarkTest01653,hash,true,328 +BenchmarkTest01654,hash,true,328 +BenchmarkTest01655,hash,false,328 +BenchmarkTest01656,hash,false,328 +BenchmarkTest01657,xss,true,79 +BenchmarkTest01658,xss,true,79 +BenchmarkTest01659,xss,false,79 +BenchmarkTest01660,xss,true,79 +BenchmarkTest01661,xss,false,79 +BenchmarkTest01662,xss,true,79 +BenchmarkTest01663,xss,false,79 +BenchmarkTest01664,xss,false,79 +BenchmarkTest01665,xss,true,79 +BenchmarkTest01666,xss,true,79 +BenchmarkTest01667,xss,true,79 +BenchmarkTest01668,xss,false,79 +BenchmarkTest01669,xss,false,79 +BenchmarkTest01670,xss,true,79 +BenchmarkTest01671,xss,false,79 +BenchmarkTest01672,cmdi,false,78 +BenchmarkTest01673,cmdi,true,78 +BenchmarkTest01674,cmdi,true,78 +BenchmarkTest01675,weakrand,true,330 +BenchmarkTest01676,weakrand,true,330 +BenchmarkTest01677,weakrand,true,330 +BenchmarkTest01678,weakrand,true,330 +BenchmarkTest01679,weakrand,true,330 +BenchmarkTest01680,weakrand,true,330 +BenchmarkTest01681,weakrand,true,330 +BenchmarkTest01682,securecookie,true,614 +BenchmarkTest01683,securecookie,true,614 +BenchmarkTest01684,securecookie,false,614 +BenchmarkTest01685,cmdi,true,78 +BenchmarkTest01686,cmdi,false,78 +BenchmarkTest01687,cmdi,false,78 +BenchmarkTest01688,cmdi,false,78 +BenchmarkTest01689,cmdi,true,78 +BenchmarkTest01690,cmdi,true,78 +BenchmarkTest01691,cmdi,true,78 +BenchmarkTest01692,cmdi,false,78 +BenchmarkTest01693,cmdi,false,78 +BenchmarkTest01694,weakrand,false,330 +BenchmarkTest01695,weakrand,false,330 +BenchmarkTest01696,weakrand,false,330 +BenchmarkTest01697,weakrand,false,330 +BenchmarkTest01698,weakrand,false,330 +BenchmarkTest01699,weakrand,false,330 +BenchmarkTest01700,weakrand,false,330 +BenchmarkTest01701,weakrand,false,330 +BenchmarkTest01702,weakrand,false,330 +BenchmarkTest01703,weakrand,false,330 +BenchmarkTest01704,weakrand,false,330 +BenchmarkTest01705,weakrand,false,330 +BenchmarkTest01706,weakrand,false,330 +BenchmarkTest01707,weakrand,false,330 +BenchmarkTest01708,trustbound,true,501 +BenchmarkTest01709,trustbound,true,501 +BenchmarkTest01710,trustbound,true,501 +BenchmarkTest01711,trustbound,true,501 +BenchmarkTest01712,sqli,true,89 +BenchmarkTest01713,sqli,false,89 +BenchmarkTest01714,sqli,false,89 +BenchmarkTest01715,sqli,true,89 +BenchmarkTest01716,sqli,true,89 +BenchmarkTest01717,sqli,false,89 +BenchmarkTest01718,sqli,true,89 +BenchmarkTest01719,sqli,false,89 +BenchmarkTest01720,sqli,true,89 +BenchmarkTest01721,sqli,true,89 +BenchmarkTest01722,sqli,false,89 +BenchmarkTest01723,sqli,true,89 +BenchmarkTest01724,sqli,true,89 +BenchmarkTest01725,sqli,true,89 +BenchmarkTest01726,sqli,true,89 +BenchmarkTest01727,sqli,true,89 +BenchmarkTest01728,sqli,true,89 +BenchmarkTest01729,sqli,false,89 +BenchmarkTest01730,sqli,true,89 +BenchmarkTest01731,sqli,true,89 +BenchmarkTest01732,sqli,false,89 +BenchmarkTest01733,sqli,true,89 +BenchmarkTest01734,xpathi,true,643 +BenchmarkTest01735,xpathi,false,643 +BenchmarkTest01736,xpathi,true,643 +BenchmarkTest01737,crypto,false,327 +BenchmarkTest01738,crypto,false,327 +BenchmarkTest01739,crypto,false,327 +BenchmarkTest01740,crypto,true,327 +BenchmarkTest01741,crypto,true,327 +BenchmarkTest01742,crypto,true,327 +BenchmarkTest01743,ldapi,false,90 +BenchmarkTest01744,pathtraver,false,22 +BenchmarkTest01745,pathtraver,false,22 +BenchmarkTest01746,pathtraver,false,22 +BenchmarkTest01747,pathtraver,false,22 +BenchmarkTest01748,pathtraver,false,22 +BenchmarkTest01749,pathtraver,false,22 +BenchmarkTest01750,pathtraver,false,22 +BenchmarkTest01751,pathtraver,false,22 +BenchmarkTest01752,pathtraver,false,22 +BenchmarkTest01753,ldapi,false,90 +BenchmarkTest01754,ldapi,false,90 +BenchmarkTest01755,ldapi,false,90 +BenchmarkTest01756,ldapi,false,90 +BenchmarkTest01757,hash,true,328 +BenchmarkTest01758,hash,false,328 +BenchmarkTest01759,hash,false,328 +BenchmarkTest01760,hash,false,328 +BenchmarkTest01761,hash,true,328 +BenchmarkTest01762,hash,false,328 +BenchmarkTest01763,hash,false,328 +BenchmarkTest01764,hash,false,328 +BenchmarkTest01765,hash,true,328 +BenchmarkTest01766,hash,true,328 +BenchmarkTest01767,xss,false,79 +BenchmarkTest01768,xss,false,79 +BenchmarkTest01769,xss,false,79 +BenchmarkTest01770,xss,false,79 +BenchmarkTest01771,xss,false,79 +BenchmarkTest01772,xss,false,79 +BenchmarkTest01773,xss,false,79 +BenchmarkTest01774,xss,false,79 +BenchmarkTest01775,xss,false,79 +BenchmarkTest01776,xss,false,79 +BenchmarkTest01777,xss,false,79 +BenchmarkTest01778,cmdi,false,78 +BenchmarkTest01779,cmdi,false,78 +BenchmarkTest01780,cmdi,false,78 +BenchmarkTest01781,weakrand,true,330 +BenchmarkTest01782,weakrand,true,330 +BenchmarkTest01783,weakrand,true,330 +BenchmarkTest01784,weakrand,true,330 +BenchmarkTest01785,weakrand,true,330 +BenchmarkTest01786,weakrand,true,330 +BenchmarkTest01787,weakrand,true,330 +BenchmarkTest01788,weakrand,true,330 +BenchmarkTest01789,securecookie,true,614 +BenchmarkTest01790,xss,false,79 +BenchmarkTest01791,cmdi,false,78 +BenchmarkTest01792,cmdi,false,78 +BenchmarkTest01793,cmdi,false,78 +BenchmarkTest01794,cmdi,false,78 +BenchmarkTest01795,cmdi,false,78 +BenchmarkTest01796,cmdi,false,78 +BenchmarkTest01797,weakrand,false,330 +BenchmarkTest01798,weakrand,false,330 +BenchmarkTest01799,weakrand,false,330 +BenchmarkTest01800,weakrand,false,330 +BenchmarkTest01801,weakrand,false,330 +BenchmarkTest01802,trustbound,false,501 +BenchmarkTest01803,sqli,false,89 +BenchmarkTest01804,sqli,false,89 +BenchmarkTest01805,sqli,false,89 +BenchmarkTest01806,sqli,false,89 +BenchmarkTest01807,sqli,false,89 +BenchmarkTest01808,sqli,false,89 +BenchmarkTest01809,sqli,false,89 +BenchmarkTest01810,sqli,false,89 +BenchmarkTest01811,sqli,false,89 +BenchmarkTest01812,sqli,false,89 +BenchmarkTest01813,sqli,false,89 +BenchmarkTest01814,sqli,false,89 +BenchmarkTest01815,sqli,false,89 +BenchmarkTest01816,sqli,false,89 +BenchmarkTest01817,sqli,false,89 +BenchmarkTest01818,sqli,false,89 +BenchmarkTest01819,sqli,false,89 +BenchmarkTest01820,sqli,false,89 +BenchmarkTest01821,xpathi,false,643 +BenchmarkTest01822,crypto,true,327 +BenchmarkTest01823,crypto,true,327 +BenchmarkTest01824,crypto,false,327 +BenchmarkTest01825,crypto,false,327 +BenchmarkTest01826,crypto,false,327 +BenchmarkTest01827,crypto,false,327 +BenchmarkTest01828,crypto,false,327 +BenchmarkTest01829,crypto,true,327 +BenchmarkTest01830,crypto,true,327 +BenchmarkTest01831,ldapi,true,90 +BenchmarkTest01832,ldapi,true,90 +BenchmarkTest01833,pathtraver,true,22 +BenchmarkTest01834,pathtraver,false,22 +BenchmarkTest01835,pathtraver,true,22 +BenchmarkTest01836,pathtraver,true,22 +BenchmarkTest01837,pathtraver,false,22 +BenchmarkTest01838,pathtraver,false,22 +BenchmarkTest01839,pathtraver,true,22 +BenchmarkTest01840,pathtraver,true,22 +BenchmarkTest01841,pathtraver,false,22 +BenchmarkTest01842,weakrand,true,330 +BenchmarkTest01843,weakrand,true,330 +BenchmarkTest01844,hash,true,328 +BenchmarkTest01845,hash,true,328 +BenchmarkTest01846,hash,true,328 +BenchmarkTest01847,hash,false,328 +BenchmarkTest01848,hash,false,328 +BenchmarkTest01849,hash,false,328 +BenchmarkTest01850,cmdi,true,78 +BenchmarkTest01851,cmdi,true,78 +BenchmarkTest01852,cmdi,true,78 +BenchmarkTest01853,weakrand,true,330 +BenchmarkTest01854,weakrand,true,330 +BenchmarkTest01855,weakrand,true,330 +BenchmarkTest01856,weakrand,true,330 +BenchmarkTest01857,weakrand,true,330 +BenchmarkTest01858,weakrand,true,330 +BenchmarkTest01859,weakrand,true,330 +BenchmarkTest01860,weakrand,true,330 +BenchmarkTest01861,securecookie,true,614 +BenchmarkTest01862,securecookie,false,614 +BenchmarkTest01863,securecookie,false,614 +BenchmarkTest01864,cmdi,true,78 +BenchmarkTest01865,cmdi,false,78 +BenchmarkTest01866,weakrand,false,330 +BenchmarkTest01867,weakrand,false,330 +BenchmarkTest01868,weakrand,false,330 +BenchmarkTest01869,weakrand,false,330 +BenchmarkTest01870,weakrand,false,330 +BenchmarkTest01871,weakrand,false,330 +BenchmarkTest01872,trustbound,true,501 +BenchmarkTest01873,trustbound,false,501 +BenchmarkTest01874,trustbound,true,501 +BenchmarkTest01875,trustbound,true,501 +BenchmarkTest01876,trustbound,true,501 +BenchmarkTest01877,sqli,false,89 +BenchmarkTest01878,sqli,false,89 +BenchmarkTest01879,sqli,false,89 +BenchmarkTest01880,sqli,false,89 +BenchmarkTest01881,sqli,true,89 +BenchmarkTest01882,sqli,true,89 +BenchmarkTest01883,sqli,true,89 +BenchmarkTest01884,sqli,false,89 +BenchmarkTest01885,sqli,false,89 +BenchmarkTest01886,sqli,false,89 +BenchmarkTest01887,sqli,true,89 +BenchmarkTest01888,sqli,true,89 +BenchmarkTest01889,sqli,true,89 +BenchmarkTest01890,sqli,true,89 +BenchmarkTest01891,sqli,true,89 +BenchmarkTest01892,xpathi,true,643 +BenchmarkTest01893,xpathi,false,643 +BenchmarkTest01894,xpathi,true,643 +BenchmarkTest01895,crypto,true,327 +BenchmarkTest01896,crypto,false,327 +BenchmarkTest01897,crypto,true,327 +BenchmarkTest01898,crypto,true,327 +BenchmarkTest01899,crypto,false,327 +BenchmarkTest01900,crypto,true,327 +BenchmarkTest01901,crypto,false,327 +BenchmarkTest01902,ldapi,true,90 +BenchmarkTest01903,ldapi,false,90 +BenchmarkTest01904,pathtraver,true,22 +BenchmarkTest01905,pathtraver,false,22 +BenchmarkTest01906,pathtraver,true,22 +BenchmarkTest01907,pathtraver,true,22 +BenchmarkTest01908,pathtraver,true,22 +BenchmarkTest01909,ldapi,false,90 +BenchmarkTest01910,weakrand,true,330 +BenchmarkTest01911,hash,true,328 +BenchmarkTest01912,hash,false,328 +BenchmarkTest01913,hash,false,328 +BenchmarkTest01914,xss,false,79 +BenchmarkTest01915,xss,false,79 +BenchmarkTest01916,xss,true,79 +BenchmarkTest01917,xss,false,79 +BenchmarkTest01918,xss,false,79 +BenchmarkTest01919,xss,true,79 +BenchmarkTest01920,xss,true,79 +BenchmarkTest01921,xss,true,79 +BenchmarkTest01922,xss,true,79 +BenchmarkTest01923,xss,true,79 +BenchmarkTest01924,xss,false,79 +BenchmarkTest01925,xss,true,79 +BenchmarkTest01926,xss,true,79 +BenchmarkTest01927,xss,true,79 +BenchmarkTest01928,cmdi,true,78 +BenchmarkTest01929,cmdi,true,78 +BenchmarkTest01930,weakrand,true,330 +BenchmarkTest01931,weakrand,true,330 +BenchmarkTest01932,weakrand,true,330 +BenchmarkTest01933,weakrand,true,330 +BenchmarkTest01934,weakrand,true,330 +BenchmarkTest01935,securecookie,false,614 +BenchmarkTest01936,cmdi,true,78 +BenchmarkTest01937,cmdi,false,78 +BenchmarkTest01938,cmdi,true,78 +BenchmarkTest01939,cmdi,false,78 +BenchmarkTest01940,cmdi,true,78 +BenchmarkTest01941,cmdi,false,78 +BenchmarkTest01942,cmdi,true,78 +BenchmarkTest01943,cmdi,false,78 +BenchmarkTest01944,cmdi,true,78 +BenchmarkTest01945,weakrand,false,330 +BenchmarkTest01946,weakrand,false,330 +BenchmarkTest01947,weakrand,false,330 +BenchmarkTest01948,weakrand,false,330 +BenchmarkTest01949,weakrand,false,330 +BenchmarkTest01950,weakrand,false,330 +BenchmarkTest01951,weakrand,false,330 +BenchmarkTest01952,weakrand,false,330 +BenchmarkTest01953,weakrand,false,330 +BenchmarkTest01954,weakrand,false,330 +BenchmarkTest01955,trustbound,true,501 +BenchmarkTest01956,trustbound,false,501 +BenchmarkTest01957,trustbound,false,501 +BenchmarkTest01958,trustbound,true,501 +BenchmarkTest01959,trustbound,false,501 +BenchmarkTest01960,trustbound,true,501 +BenchmarkTest01961,sqli,false,89 +BenchmarkTest01962,sqli,true,89 +BenchmarkTest01963,sqli,true,89 +BenchmarkTest01964,sqli,true,89 +BenchmarkTest01965,sqli,false,89 +BenchmarkTest01966,sqli,false,89 +BenchmarkTest01967,sqli,false,89 +BenchmarkTest01968,sqli,false,89 +BenchmarkTest01969,sqli,false,89 +BenchmarkTest01970,sqli,true,89 +BenchmarkTest01971,sqli,true,89 +BenchmarkTest01972,sqli,true,89 +BenchmarkTest01973,sqli,false,89 +BenchmarkTest01974,xpathi,true,643 +BenchmarkTest01975,crypto,false,327 +BenchmarkTest01976,crypto,false,327 +BenchmarkTest01977,crypto,false,327 +BenchmarkTest01978,crypto,true,327 +BenchmarkTest01979,crypto,false,327 +BenchmarkTest01980,crypto,true,327 +BenchmarkTest01981,crypto,true,327 +BenchmarkTest01982,crypto,false,327 +BenchmarkTest01983,pathtraver,true,22 +BenchmarkTest01984,pathtraver,false,22 +BenchmarkTest01985,pathtraver,true,22 +BenchmarkTest01986,pathtraver,false,22 +BenchmarkTest01987,pathtraver,true,22 +BenchmarkTest01988,pathtraver,true,22 +BenchmarkTest01989,pathtraver,true,22 +BenchmarkTest01990,pathtraver,false,22 +BenchmarkTest01991,pathtraver,false,22 +BenchmarkTest01992,weakrand,true,330 +BenchmarkTest01993,hash,false,328 +BenchmarkTest01994,hash,false,328 +BenchmarkTest01995,hash,false,328 +BenchmarkTest01996,hash,true,328 +BenchmarkTest01997,hash,true,328 +BenchmarkTest01998,hash,false,328 +BenchmarkTest01999,weakrand,true,330 +BenchmarkTest02000,weakrand,true,330 +BenchmarkTest02001,weakrand,true,330 +BenchmarkTest02002,weakrand,true,330 +BenchmarkTest02003,weakrand,true,330 +BenchmarkTest02004,weakrand,true,330 +BenchmarkTest02005,securecookie,true,614 +BenchmarkTest02006,securecookie,false,614 +BenchmarkTest02007,weakrand,false,330 +BenchmarkTest02008,weakrand,false,330 +BenchmarkTest02009,weakrand,false,330 +BenchmarkTest02010,weakrand,false,330 +BenchmarkTest02011,weakrand,false,330 +BenchmarkTest02012,weakrand,false,330 +BenchmarkTest02013,weakrand,false,330 +BenchmarkTest02014,weakrand,false,330 +BenchmarkTest02015,trustbound,true,501 +BenchmarkTest02016,trustbound,true,501 +BenchmarkTest02017,crypto,true,327 +BenchmarkTest02018,crypto,true,327 +BenchmarkTest02019,crypto,true,327 +BenchmarkTest02020,crypto,true,327 +BenchmarkTest02021,crypto,false,327 +BenchmarkTest02022,crypto,true,327 +BenchmarkTest02023,crypto,true,327 +BenchmarkTest02024,crypto,false,327 +BenchmarkTest02025,ldapi,false,90 +BenchmarkTest02026,pathtraver,false,22 +BenchmarkTest02027,pathtraver,true,22 +BenchmarkTest02028,pathtraver,false,22 +BenchmarkTest02029,pathtraver,false,22 +BenchmarkTest02030,pathtraver,false,22 +BenchmarkTest02031,pathtraver,false,22 +BenchmarkTest02032,pathtraver,true,22 +BenchmarkTest02033,pathtraver,false,22 +BenchmarkTest02034,pathtraver,true,22 +BenchmarkTest02035,pathtraver,false,22 +BenchmarkTest02036,ldapi,true,90 +BenchmarkTest02037,ldapi,true,90 +BenchmarkTest02038,weakrand,true,330 +BenchmarkTest02039,weakrand,true,330 +BenchmarkTest02040,weakrand,true,330 +BenchmarkTest02041,hash,false,328 +BenchmarkTest02042,hash,true,328 +BenchmarkTest02043,hash,false,328 +BenchmarkTest02044,hash,false,328 +BenchmarkTest02045,xss,false,79 +BenchmarkTest02046,xss,true,79 +BenchmarkTest02047,xss,true,79 +BenchmarkTest02048,xss,false,79 +BenchmarkTest02049,xss,false,79 +BenchmarkTest02050,xss,true,79 +BenchmarkTest02051,xss,true,79 +BenchmarkTest02052,xss,false,79 +BenchmarkTest02053,xss,false,79 +BenchmarkTest02054,xss,true,79 +BenchmarkTest02055,xss,true,79 +BenchmarkTest02056,xss,true,79 +BenchmarkTest02057,xss,true,79 +BenchmarkTest02058,cmdi,false,78 +BenchmarkTest02059,cmdi,true,78 +BenchmarkTest02060,weakrand,true,330 +BenchmarkTest02061,weakrand,true,330 +BenchmarkTest02062,weakrand,true,330 +BenchmarkTest02063,weakrand,true,330 +BenchmarkTest02064,securecookie,false,614 +BenchmarkTest02065,securecookie,false,614 +BenchmarkTest02066,securecookie,false,614 +BenchmarkTest02067,cmdi,false,78 +BenchmarkTest02068,cmdi,false,78 +BenchmarkTest02069,cmdi,false,78 +BenchmarkTest02070,cmdi,true,78 +BenchmarkTest02071,weakrand,false,330 +BenchmarkTest02072,weakrand,false,330 +BenchmarkTest02073,weakrand,false,330 +BenchmarkTest02074,weakrand,false,330 +BenchmarkTest02075,weakrand,false,330 +BenchmarkTest02076,weakrand,false,330 +BenchmarkTest02077,weakrand,false,330 +BenchmarkTest02078,weakrand,false,330 +BenchmarkTest02079,weakrand,false,330 +BenchmarkTest02080,weakrand,false,330 +BenchmarkTest02081,weakrand,false,330 +BenchmarkTest02082,weakrand,false,330 +BenchmarkTest02083,weakrand,false,330 +BenchmarkTest02084,trustbound,true,501 +BenchmarkTest02085,trustbound,false,501 +BenchmarkTest02086,trustbound,false,501 +BenchmarkTest02087,sqli,true,89 +BenchmarkTest02088,sqli,true,89 +BenchmarkTest02089,sqli,false,89 +BenchmarkTest02090,sqli,true,89 +BenchmarkTest02091,sqli,true,89 +BenchmarkTest02092,sqli,true,89 +BenchmarkTest02093,sqli,false,89 +BenchmarkTest02094,sqli,true,89 +BenchmarkTest02095,sqli,false,89 +BenchmarkTest02096,sqli,true,89 +BenchmarkTest02097,sqli,false,89 +BenchmarkTest02098,sqli,false,89 +BenchmarkTest02099,sqli,true,89 +BenchmarkTest02100,xpathi,true,643 +BenchmarkTest02101,crypto,true,327 +BenchmarkTest02102,crypto,false,327 +BenchmarkTest02103,crypto,false,327 +BenchmarkTest02104,ldapi,false,90 +BenchmarkTest02105,pathtraver,true,22 +BenchmarkTest02106,pathtraver,true,22 +BenchmarkTest02107,pathtraver,false,22 +BenchmarkTest02108,pathtraver,false,22 +BenchmarkTest02109,pathtraver,true,22 +BenchmarkTest02110,pathtraver,false,22 +BenchmarkTest02111,pathtraver,false,22 +BenchmarkTest02112,pathtraver,true,22 +BenchmarkTest02113,pathtraver,true,22 +BenchmarkTest02114,ldapi,false,90 +BenchmarkTest02115,ldapi,false,90 +BenchmarkTest02116,ldapi,false,90 +BenchmarkTest02117,weakrand,true,330 +BenchmarkTest02118,hash,true,328 +BenchmarkTest02119,hash,false,328 +BenchmarkTest02120,hash,false,328 +BenchmarkTest02121,hash,true,328 +BenchmarkTest02122,xss,false,79 +BenchmarkTest02123,xss,true,79 +BenchmarkTest02124,xss,true,79 +BenchmarkTest02125,xss,false,79 +BenchmarkTest02126,xss,true,79 +BenchmarkTest02127,xss,true,79 +BenchmarkTest02128,xss,true,79 +BenchmarkTest02129,xss,true,79 +BenchmarkTest02130,xss,true,79 +BenchmarkTest02131,xss,true,79 +BenchmarkTest02132,xss,true,79 +BenchmarkTest02133,xss,true,79 +BenchmarkTest02134,xss,true,79 +BenchmarkTest02135,xss,false,79 +BenchmarkTest02136,xss,true,79 +BenchmarkTest02137,cmdi,true,78 +BenchmarkTest02138,weakrand,true,330 +BenchmarkTest02139,weakrand,true,330 +BenchmarkTest02140,weakrand,true,330 +BenchmarkTest02141,weakrand,true,330 +BenchmarkTest02142,securecookie,true,614 +BenchmarkTest02143,securecookie,false,614 +BenchmarkTest02144,securecookie,false,614 +BenchmarkTest02145,xss,true,79 +BenchmarkTest02146,cmdi,true,78 +BenchmarkTest02147,cmdi,true,78 +BenchmarkTest02148,cmdi,false,78 +BenchmarkTest02149,cmdi,false,78 +BenchmarkTest02150,cmdi,true,78 +BenchmarkTest02151,cmdi,true,78 +BenchmarkTest02152,cmdi,true,78 +BenchmarkTest02153,cmdi,false,78 +BenchmarkTest02154,cmdi,true,78 +BenchmarkTest02155,cmdi,true,78 +BenchmarkTest02156,cmdi,false,78 +BenchmarkTest02157,weakrand,false,330 +BenchmarkTest02158,weakrand,false,330 +BenchmarkTest02159,weakrand,false,330 +BenchmarkTest02160,weakrand,false,330 +BenchmarkTest02161,weakrand,false,330 +BenchmarkTest02162,weakrand,false,330 +BenchmarkTest02163,weakrand,false,330 +BenchmarkTest02164,weakrand,false,330 +BenchmarkTest02165,trustbound,true,501 +BenchmarkTest02166,trustbound,false,501 +BenchmarkTest02167,trustbound,true,501 +BenchmarkTest02168,trustbound,false,501 +BenchmarkTest02169,sqli,true,89 +BenchmarkTest02170,sqli,true,89 +BenchmarkTest02171,sqli,true,89 +BenchmarkTest02172,sqli,false,89 +BenchmarkTest02173,sqli,false,89 +BenchmarkTest02174,sqli,false,89 +BenchmarkTest02175,sqli,false,89 +BenchmarkTest02176,sqli,false,89 +BenchmarkTest02177,sqli,true,89 +BenchmarkTest02178,sqli,true,89 +BenchmarkTest02179,sqli,true,89 +BenchmarkTest02180,sqli,false,89 +BenchmarkTest02181,sqli,true,89 +BenchmarkTest02182,sqli,true,89 +BenchmarkTest02183,sqli,false,89 +BenchmarkTest02184,sqli,false,89 +BenchmarkTest02185,sqli,false,89 +BenchmarkTest02186,sqli,true,89 +BenchmarkTest02187,sqli,true,89 +BenchmarkTest02188,sqli,false,89 +BenchmarkTest02189,xpathi,true,643 +BenchmarkTest02190,crypto,false,327 +BenchmarkTest02191,crypto,false,327 +BenchmarkTest02192,crypto,true,327 +BenchmarkTest02193,crypto,true,327 +BenchmarkTest02194,crypto,true,327 +BenchmarkTest02195,crypto,true,327 +BenchmarkTest02196,ldapi,true,90 +BenchmarkTest02197,pathtraver,true,22 +BenchmarkTest02198,pathtraver,true,22 +BenchmarkTest02199,pathtraver,true,22 +BenchmarkTest02200,pathtraver,false,22 +BenchmarkTest02201,pathtraver,false,22 +BenchmarkTest02202,pathtraver,false,22 +BenchmarkTest02203,pathtraver,false,22 +BenchmarkTest02204,pathtraver,false,22 +BenchmarkTest02205,pathtraver,true,22 +BenchmarkTest02206,pathtraver,false,22 +BenchmarkTest02207,pathtraver,false,22 +BenchmarkTest02208,ldapi,true,90 +BenchmarkTest02209,weakrand,true,330 +BenchmarkTest02210,hash,false,328 +BenchmarkTest02211,hash,true,328 +BenchmarkTest02212,hash,true,328 +BenchmarkTest02213,hash,true,328 +BenchmarkTest02214,hash,false,328 +BenchmarkTest02215,hash,false,328 +BenchmarkTest02216,hash,false,328 +BenchmarkTest02217,hash,true,328 +BenchmarkTest02218,hash,false,328 +BenchmarkTest02219,hash,true,328 +BenchmarkTest02220,hash,false,328 +BenchmarkTest02221,xss,true,79 +BenchmarkTest02222,xss,false,79 +BenchmarkTest02223,xss,true,79 +BenchmarkTest02224,xss,true,79 +BenchmarkTest02225,xss,true,79 +BenchmarkTest02226,xss,false,79 +BenchmarkTest02227,xss,true,79 +BenchmarkTest02228,xss,true,79 +BenchmarkTest02229,xss,false,79 +BenchmarkTest02230,xss,true,79 +BenchmarkTest02231,xss,false,79 +BenchmarkTest02232,xss,true,79 +BenchmarkTest02233,xss,false,79 +BenchmarkTest02234,xss,true,79 +BenchmarkTest02235,xss,false,79 +BenchmarkTest02236,xss,false,79 +BenchmarkTest02237,xss,false,79 +BenchmarkTest02238,xss,false,79 +BenchmarkTest02239,xss,false,79 +BenchmarkTest02240,xss,false,79 +BenchmarkTest02241,xss,true,79 +BenchmarkTest02242,cmdi,false,78 +BenchmarkTest02243,cmdi,true,78 +BenchmarkTest02244,cmdi,true,78 +BenchmarkTest02245,weakrand,true,330 +BenchmarkTest02246,weakrand,true,330 +BenchmarkTest02247,securecookie,false,614 +BenchmarkTest02248,securecookie,false,614 +BenchmarkTest02249,cmdi,true,78 +BenchmarkTest02250,cmdi,true,78 +BenchmarkTest02251,cmdi,true,78 +BenchmarkTest02252,cmdi,false,78 +BenchmarkTest02253,cmdi,false,78 +BenchmarkTest02254,weakrand,false,330 +BenchmarkTest02255,weakrand,false,330 +BenchmarkTest02256,weakrand,false,330 +BenchmarkTest02257,weakrand,false,330 +BenchmarkTest02258,weakrand,false,330 +BenchmarkTest02259,weakrand,false,330 +BenchmarkTest02260,weakrand,false,330 +BenchmarkTest02261,trustbound,true,501 +BenchmarkTest02262,trustbound,true,501 +BenchmarkTest02263,trustbound,true,501 +BenchmarkTest02264,sqli,true,89 +BenchmarkTest02265,sqli,false,89 +BenchmarkTest02266,sqli,false,89 +BenchmarkTest02267,sqli,false,89 +BenchmarkTest02268,sqli,false,89 +BenchmarkTest02269,sqli,true,89 +BenchmarkTest02270,sqli,true,89 +BenchmarkTest02271,sqli,false,89 +BenchmarkTest02272,sqli,true,89 +BenchmarkTest02273,sqli,true,89 +BenchmarkTest02274,sqli,false,89 +BenchmarkTest02275,sqli,true,89 +BenchmarkTest02276,sqli,false,89 +BenchmarkTest02277,sqli,true,89 +BenchmarkTest02278,sqli,false,89 +BenchmarkTest02279,sqli,false,89 +BenchmarkTest02280,sqli,false,89 +BenchmarkTest02281,sqli,true,89 +BenchmarkTest02282,sqli,false,89 +BenchmarkTest02283,sqli,false,89 +BenchmarkTest02284,sqli,true,89 +BenchmarkTest02285,sqli,false,89 +BenchmarkTest02286,sqli,true,89 +BenchmarkTest02287,sqli,true,89 +BenchmarkTest02288,sqli,true,89 +BenchmarkTest02289,crypto,false,327 +BenchmarkTest02290,crypto,true,327 +BenchmarkTest02291,crypto,true,327 +BenchmarkTest02292,crypto,true,327 +BenchmarkTest02293,crypto,true,327 +BenchmarkTest02294,crypto,true,327 +BenchmarkTest02295,crypto,true,327 +BenchmarkTest02296,crypto,false,327 +BenchmarkTest02297,crypto,false,327 +BenchmarkTest02298,crypto,false,327 +BenchmarkTest02299,ldapi,true,90 +BenchmarkTest02300,pathtraver,false,22 +BenchmarkTest02301,pathtraver,false,22 +BenchmarkTest02302,pathtraver,true,22 +BenchmarkTest02303,pathtraver,true,22 +BenchmarkTest02304,pathtraver,true,22 +BenchmarkTest02305,ldapi,true,90 +BenchmarkTest02306,ldapi,true,90 +BenchmarkTest02307,hash,true,328 +BenchmarkTest02308,hash,true,328 +BenchmarkTest02309,hash,false,328 +BenchmarkTest02310,hash,false,328 +BenchmarkTest02311,hash,true,328 +BenchmarkTest02312,hash,false,328 +BenchmarkTest02313,xss,false,79 +BenchmarkTest02314,xss,true,79 +BenchmarkTest02315,xss,true,79 +BenchmarkTest02316,xss,true,79 +BenchmarkTest02317,xss,true,79 +BenchmarkTest02318,xss,false,79 +BenchmarkTest02319,xss,false,79 +BenchmarkTest02320,xss,false,79 +BenchmarkTest02321,xss,true,79 +BenchmarkTest02322,xss,true,79 +BenchmarkTest02323,xss,true,79 +BenchmarkTest02324,xss,true,79 +BenchmarkTest02325,xss,false,79 +BenchmarkTest02326,xss,true,79 +BenchmarkTest02327,xss,true,79 +BenchmarkTest02328,xss,true,79 +BenchmarkTest02329,xss,false,79 +BenchmarkTest02330,xss,false,79 +BenchmarkTest02331,xss,false,79 +BenchmarkTest02332,xss,true,79 +BenchmarkTest02333,cmdi,true,78 +BenchmarkTest02334,cmdi,true,78 +BenchmarkTest02335,cmdi,false,78 +BenchmarkTest02336,cmdi,false,78 +BenchmarkTest02337,weakrand,true,330 +BenchmarkTest02338,weakrand,true,330 +BenchmarkTest02339,securecookie,true,614 +BenchmarkTest02340,cmdi,false,78 +BenchmarkTest02341,cmdi,false,78 +BenchmarkTest02342,cmdi,true,78 +BenchmarkTest02343,cmdi,true,78 +BenchmarkTest02344,cmdi,true,78 +BenchmarkTest02345,weakrand,false,330 +BenchmarkTest02346,weakrand,false,330 +BenchmarkTest02347,weakrand,false,330 +BenchmarkTest02348,weakrand,false,330 +BenchmarkTest02349,weakrand,false,330 +BenchmarkTest02350,weakrand,false,330 +BenchmarkTest02351,weakrand,false,330 +BenchmarkTest02352,trustbound,true,501 +BenchmarkTest02353,sqli,false,89 +BenchmarkTest02354,sqli,true,89 +BenchmarkTest02355,sqli,true,89 +BenchmarkTest02356,sqli,true,89 +BenchmarkTest02357,sqli,true,89 +BenchmarkTest02358,sqli,true,89 +BenchmarkTest02359,sqli,true,89 +BenchmarkTest02360,sqli,true,89 +BenchmarkTest02361,sqli,false,89 +BenchmarkTest02362,sqli,true,89 +BenchmarkTest02363,sqli,false,89 +BenchmarkTest02364,sqli,true,89 +BenchmarkTest02365,sqli,false,89 +BenchmarkTest02366,sqli,false,89 +BenchmarkTest02367,sqli,false,89 +BenchmarkTest02368,sqli,false,89 +BenchmarkTest02369,sqli,true,89 +BenchmarkTest02370,xpathi,false,643 +BenchmarkTest02371,crypto,false,327 +BenchmarkTest02372,crypto,false,327 +BenchmarkTest02373,crypto,true,327 +BenchmarkTest02374,crypto,true,327 +BenchmarkTest02375,crypto,true,327 +BenchmarkTest02376,ldapi,false,90 +BenchmarkTest02377,pathtraver,true,22 +BenchmarkTest02378,pathtraver,true,22 +BenchmarkTest02379,pathtraver,false,22 +BenchmarkTest02380,pathtraver,false,22 +BenchmarkTest02381,pathtraver,false,22 +BenchmarkTest02382,pathtraver,false,22 +BenchmarkTest02383,pathtraver,true,22 +BenchmarkTest02384,ldapi,false,90 +BenchmarkTest02385,hash,true,328 +BenchmarkTest02386,hash,true,328 +BenchmarkTest02387,hash,true,328 +BenchmarkTest02388,hash,true,328 +BenchmarkTest02389,hash,false,328 +BenchmarkTest02390,hash,false,328 +BenchmarkTest02391,hash,true,328 +BenchmarkTest02392,hash,true,328 +BenchmarkTest02393,hash,true,328 +BenchmarkTest02394,xss,false,79 +BenchmarkTest02395,xss,true,79 +BenchmarkTest02396,xss,true,79 +BenchmarkTest02397,xss,true,79 +BenchmarkTest02398,xss,false,79 +BenchmarkTest02399,xss,true,79 +BenchmarkTest02400,xss,true,79 +BenchmarkTest02401,xss,false,79 +BenchmarkTest02402,xss,true,79 +BenchmarkTest02403,xss,true,79 +BenchmarkTest02404,xss,false,79 +BenchmarkTest02405,xss,true,79 +BenchmarkTest02406,xss,false,79 +BenchmarkTest02407,xss,true,79 +BenchmarkTest02408,xss,false,79 +BenchmarkTest02409,xss,true,79 +BenchmarkTest02410,xss,true,79 +BenchmarkTest02411,cmdi,true,78 +BenchmarkTest02412,cmdi,true,78 +BenchmarkTest02413,cmdi,false,78 +BenchmarkTest02414,cmdi,true,78 +BenchmarkTest02415,weakrand,true,330 +BenchmarkTest02416,weakrand,true,330 +BenchmarkTest02417,weakrand,true,330 +BenchmarkTest02418,weakrand,true,330 +BenchmarkTest02419,weakrand,true,330 +BenchmarkTest02420,weakrand,true,330 +BenchmarkTest02421,weakrand,true,330 +BenchmarkTest02422,weakrand,true,330 +BenchmarkTest02423,weakrand,true,330 +BenchmarkTest02424,weakrand,true,330 +BenchmarkTest02425,weakrand,true,330 +BenchmarkTest02426,weakrand,true,330 +BenchmarkTest02427,securecookie,true,614 +BenchmarkTest02428,cmdi,false,78 +BenchmarkTest02429,cmdi,true,78 +BenchmarkTest02430,cmdi,true,78 +BenchmarkTest02431,cmdi,true,78 +BenchmarkTest02432,cmdi,true,78 +BenchmarkTest02433,cmdi,true,78 +BenchmarkTest02434,weakrand,false,330 +BenchmarkTest02435,weakrand,false,330 +BenchmarkTest02436,weakrand,false,330 +BenchmarkTest02437,weakrand,false,330 +BenchmarkTest02438,weakrand,false,330 +BenchmarkTest02439,weakrand,false,330 +BenchmarkTest02440,weakrand,false,330 +BenchmarkTest02441,weakrand,false,330 +BenchmarkTest02442,weakrand,false,330 +BenchmarkTest02443,weakrand,false,330 +BenchmarkTest02444,weakrand,false,330 +BenchmarkTest02445,weakrand,false,330 +BenchmarkTest02446,trustbound,true,501 +BenchmarkTest02447,trustbound,false,501 +BenchmarkTest02448,trustbound,true,501 +BenchmarkTest02449,sqli,true,89 +BenchmarkTest02450,sqli,false,89 +BenchmarkTest02451,sqli,true,89 +BenchmarkTest02452,sqli,false,89 +BenchmarkTest02453,sqli,true,89 +BenchmarkTest02454,sqli,true,89 +BenchmarkTest02455,sqli,true,89 +BenchmarkTest02456,sqli,false,89 +BenchmarkTest02457,xpathi,false,643 +BenchmarkTest02458,crypto,true,327 +BenchmarkTest02459,crypto,false,327 +BenchmarkTest02460,crypto,false,327 +BenchmarkTest02461,crypto,false,327 +BenchmarkTest02462,pathtraver,false,22 +BenchmarkTest02463,pathtraver,true,22 +BenchmarkTest02464,pathtraver,false,22 +BenchmarkTest02465,pathtraver,true,22 +BenchmarkTest02466,pathtraver,true,22 +BenchmarkTest02467,pathtraver,false,22 +BenchmarkTest02468,pathtraver,false,22 +BenchmarkTest02469,pathtraver,true,22 +BenchmarkTest02470,pathtraver,false,22 +BenchmarkTest02471,pathtraver,false,22 +BenchmarkTest02472,ldapi,true,90 +BenchmarkTest02473,weakrand,true,330 +BenchmarkTest02474,hash,true,328 +BenchmarkTest02475,hash,true,328 +BenchmarkTest02476,hash,true,328 +BenchmarkTest02477,hash,false,328 +BenchmarkTest02478,hash,true,328 +BenchmarkTest02479,hash,false,328 +BenchmarkTest02480,xss,true,79 +BenchmarkTest02481,xss,false,79 +BenchmarkTest02482,xss,false,79 +BenchmarkTest02483,xss,true,79 +BenchmarkTest02484,xss,false,79 +BenchmarkTest02485,xss,false,79 +BenchmarkTest02486,xss,true,79 +BenchmarkTest02487,xss,true,79 +BenchmarkTest02488,xss,false,79 +BenchmarkTest02489,xss,true,79 +BenchmarkTest02490,xss,false,79 +BenchmarkTest02491,xss,false,79 +BenchmarkTest02492,xss,false,79 +BenchmarkTest02493,xss,true,79 +BenchmarkTest02494,xss,true,79 +BenchmarkTest02495,xss,false,79 +BenchmarkTest02496,cmdi,true,78 +BenchmarkTest02497,weakrand,true,330 +BenchmarkTest02498,weakrand,true,330 +BenchmarkTest02499,weakrand,true,330 +BenchmarkTest02500,weakrand,true,330 +BenchmarkTest02501,weakrand,true,330 +BenchmarkTest02502,weakrand,true,330 +BenchmarkTest02503,weakrand,true,330 +BenchmarkTest02504,weakrand,true,330 +BenchmarkTest02505,weakrand,true,330 +BenchmarkTest02506,weakrand,true,330 +BenchmarkTest02507,securecookie,true,614 +BenchmarkTest02508,securecookie,false,614 +BenchmarkTest02509,xss,false,79 +BenchmarkTest02510,cmdi,false,78 +BenchmarkTest02511,cmdi,true,78 +BenchmarkTest02512,cmdi,true,78 +BenchmarkTest02513,cmdi,false,78 +BenchmarkTest02514,cmdi,true,78 +BenchmarkTest02515,cmdi,true,78 +BenchmarkTest02516,cmdi,true,78 +BenchmarkTest02517,cmdi,true,78 +BenchmarkTest02518,cmdi,false,78 +BenchmarkTest02519,weakrand,false,330 +BenchmarkTest02520,weakrand,false,330 +BenchmarkTest02521,weakrand,false,330 +BenchmarkTest02522,weakrand,false,330 +BenchmarkTest02523,trustbound,false,501 +BenchmarkTest02524,trustbound,true,501 +BenchmarkTest02525,trustbound,true,501 +BenchmarkTest02526,trustbound,true,501 +BenchmarkTest02527,trustbound,true,501 +BenchmarkTest02528,sqli,true,89 +BenchmarkTest02529,sqli,false,89 +BenchmarkTest02530,sqli,true,89 +BenchmarkTest02531,sqli,true,89 +BenchmarkTest02532,sqli,true,89 +BenchmarkTest02533,sqli,true,89 +BenchmarkTest02534,sqli,true,89 +BenchmarkTest02535,sqli,true,89 +BenchmarkTest02536,sqli,false,89 +BenchmarkTest02537,sqli,true,89 +BenchmarkTest02538,sqli,false,89 +BenchmarkTest02539,sqli,false,89 +BenchmarkTest02540,sqli,false,89 +BenchmarkTest02541,sqli,false,89 +BenchmarkTest02542,sqli,true,89 +BenchmarkTest02543,sqli,true,89 +BenchmarkTest02544,sqli,false,89 +BenchmarkTest02545,sqli,true,89 +BenchmarkTest02546,sqli,false,89 +BenchmarkTest02547,crypto,false,327 +BenchmarkTest02548,crypto,true,327 +BenchmarkTest02549,crypto,true,327 +BenchmarkTest02550,crypto,true,327 +BenchmarkTest02551,crypto,false,327 +BenchmarkTest02552,crypto,false,327 +BenchmarkTest02553,ldapi,false,90 +BenchmarkTest02554,pathtraver,false,22 +BenchmarkTest02555,pathtraver,true,22 +BenchmarkTest02556,pathtraver,true,22 +BenchmarkTest02557,pathtraver,false,22 +BenchmarkTest02558,pathtraver,false,22 +BenchmarkTest02559,pathtraver,true,22 +BenchmarkTest02560,pathtraver,true,22 +BenchmarkTest02561,pathtraver,true,22 +BenchmarkTest02562,pathtraver,true,22 +BenchmarkTest02563,pathtraver,false,22 +BenchmarkTest02564,pathtraver,true,22 +BenchmarkTest02565,pathtraver,true,22 +BenchmarkTest02566,pathtraver,false,22 +BenchmarkTest02567,pathtraver,true,22 +BenchmarkTest02568,pathtraver,false,22 +BenchmarkTest02569,pathtraver,true,22 +BenchmarkTest02570,pathtraver,false,22 +BenchmarkTest02571,ldapi,false,90 +BenchmarkTest02572,ldapi,false,90 +BenchmarkTest02573,hash,true,328 +BenchmarkTest02574,hash,true,328 +BenchmarkTest02575,hash,true,328 +BenchmarkTest02576,hash,false,328 +BenchmarkTest02577,hash,true,328 +BenchmarkTest02578,xss,true,79 +BenchmarkTest02579,xss,true,79 +BenchmarkTest02580,xss,true,79 +BenchmarkTest02581,xss,false,79 +BenchmarkTest02582,xss,true,79 +BenchmarkTest02583,xss,true,79 +BenchmarkTest02584,xss,true,79 +BenchmarkTest02585,xss,true,79 +BenchmarkTest02586,xss,true,79 +BenchmarkTest02587,xss,true,79 +BenchmarkTest02588,xss,true,79 +BenchmarkTest02589,xss,false,79 +BenchmarkTest02590,xss,false,79 +BenchmarkTest02591,xss,true,79 +BenchmarkTest02592,xss,true,79 +BenchmarkTest02593,xss,false,79 +BenchmarkTest02594,xss,false,79 +BenchmarkTest02595,xss,true,79 +BenchmarkTest02596,xss,false,79 +BenchmarkTest02597,xss,true,79 +BenchmarkTest02598,xss,true,79 +BenchmarkTest02599,xss,false,79 +BenchmarkTest02600,xss,true,79 +BenchmarkTest02601,xss,false,79 +BenchmarkTest02602,weakrand,true,330 +BenchmarkTest02603,weakrand,true,330 +BenchmarkTest02604,weakrand,true,330 +BenchmarkTest02605,weakrand,true,330 +BenchmarkTest02606,weakrand,true,330 +BenchmarkTest02607,securecookie,false,614 +BenchmarkTest02608,xss,true,79 +BenchmarkTest02609,xss,false,79 +BenchmarkTest02610,cmdi,false,78 +BenchmarkTest02611,cmdi,true,78 +BenchmarkTest02612,cmdi,true,78 +BenchmarkTest02613,cmdi,true,78 +BenchmarkTest02614,weakrand,false,330 +BenchmarkTest02615,weakrand,false,330 +BenchmarkTest02616,weakrand,false,330 +BenchmarkTest02617,weakrand,false,330 +BenchmarkTest02618,weakrand,false,330 +BenchmarkTest02619,weakrand,false,330 +BenchmarkTest02620,weakrand,false,330 +BenchmarkTest02621,weakrand,false,330 +BenchmarkTest02622,trustbound,true,501 +BenchmarkTest02623,trustbound,true,501 +BenchmarkTest02624,trustbound,true,501 +BenchmarkTest02625,sqli,true,89 +BenchmarkTest02626,sqli,false,89 +BenchmarkTest02627,sqli,true,89 +BenchmarkTest02628,sqli,true,89 +BenchmarkTest02629,sqli,false,89 +BenchmarkTest02630,sqli,true,89 +BenchmarkTest02631,sqli,false,89 +BenchmarkTest02632,sqli,true,89 +BenchmarkTest02633,sqli,false,89 +BenchmarkTest02634,sqli,false,89 +BenchmarkTest02635,sqli,true,89 +BenchmarkTest02636,sqli,false,89 +BenchmarkTest02637,sqli,false,89 +BenchmarkTest02638,sqli,true,89 +BenchmarkTest02639,sqli,false,89 +BenchmarkTest02640,sqli,false,89 +BenchmarkTest02641,sqli,true,89 +BenchmarkTest02642,sqli,true,89 +BenchmarkTest02643,sqli,true,89 +BenchmarkTest02644,sqli,true,89 +BenchmarkTest02645,sqli,true,89 +BenchmarkTest02646,sqli,true,89 +BenchmarkTest02647,sqli,true,89 +BenchmarkTest02648,sqli,false,89 +BenchmarkTest02649,sqli,true,89 +BenchmarkTest02650,sqli,true,89 +BenchmarkTest02651,sqli,true,89 +BenchmarkTest02652,sqli,false,89 +BenchmarkTest02653,sqli,true,89 +BenchmarkTest02654,sqli,true,89 +BenchmarkTest02655,sqli,true,89 +BenchmarkTest02656,sqli,true,89 +BenchmarkTest02657,sqli,false,89 +BenchmarkTest02658,crypto,true,327 +BenchmarkTest02659,crypto,false,327 +BenchmarkTest02660,crypto,true,327 +BenchmarkTest02661,crypto,true,327 +BenchmarkTest02662,crypto,false,327 +BenchmarkTest02663,crypto,true,327 +BenchmarkTest02664,pathtraver,false,22 +BenchmarkTest02665,pathtraver,false,22 +BenchmarkTest02666,pathtraver,false,22 +BenchmarkTest02667,pathtraver,false,22 +BenchmarkTest02668,pathtraver,false,22 +BenchmarkTest02669,pathtraver,false,22 +BenchmarkTest02670,hash,true,328 +BenchmarkTest02671,hash,true,328 +BenchmarkTest02672,hash,false,328 +BenchmarkTest02673,hash,false,328 +BenchmarkTest02674,hash,true,328 +BenchmarkTest02675,hash,true,328 +BenchmarkTest02676,hash,false,328 +BenchmarkTest02677,hash,true,328 +BenchmarkTest02678,hash,false,328 +BenchmarkTest02679,xss,false,79 +BenchmarkTest02680,xss,false,79 +BenchmarkTest02681,xss,false,79 +BenchmarkTest02682,xss,false,79 +BenchmarkTest02683,xss,false,79 +BenchmarkTest02684,xss,false,79 +BenchmarkTest02685,xss,false,79 +BenchmarkTest02686,xss,false,79 +BenchmarkTest02687,xss,false,79 +BenchmarkTest02688,xss,false,79 +BenchmarkTest02689,xss,false,79 +BenchmarkTest02690,xss,false,79 +BenchmarkTest02691,xss,false,79 +BenchmarkTest02692,xss,false,79 +BenchmarkTest02693,xss,false,79 +BenchmarkTest02694,xss,false,79 +BenchmarkTest02695,xss,false,79 +BenchmarkTest02696,xss,false,79 +BenchmarkTest02697,cmdi,false,78 +BenchmarkTest02698,cmdi,false,78 +BenchmarkTest02699,cmdi,false,78 +BenchmarkTest02700,weakrand,true,330 +BenchmarkTest02701,weakrand,true,330 +BenchmarkTest02702,weakrand,true,330 +BenchmarkTest02703,weakrand,true,330 +BenchmarkTest02704,weakrand,true,330 +BenchmarkTest02705,weakrand,true,330 +BenchmarkTest02706,weakrand,true,330 +BenchmarkTest02707,weakrand,true,330 +BenchmarkTest02708,weakrand,true,330 +BenchmarkTest02709,securecookie,true,614 +BenchmarkTest02710,securecookie,true,614 +BenchmarkTest02711,securecookie,false,614 +BenchmarkTest02712,xss,false,79 +BenchmarkTest02713,cmdi,false,78 +BenchmarkTest02714,cmdi,false,78 +BenchmarkTest02715,weakrand,false,330 +BenchmarkTest02716,weakrand,false,330 +BenchmarkTest02717,weakrand,false,330 +BenchmarkTest02718,weakrand,false,330 +BenchmarkTest02719,weakrand,false,330 +BenchmarkTest02720,weakrand,false,330 +BenchmarkTest02721,weakrand,false,330 +BenchmarkTest02722,trustbound,false,501 +BenchmarkTest02723,trustbound,false,501 +BenchmarkTest02724,trustbound,false,501 +BenchmarkTest02725,trustbound,false,501 +BenchmarkTest02726,trustbound,false,501 +BenchmarkTest02727,sqli,false,89 +BenchmarkTest02728,sqli,false,89 +BenchmarkTest02729,sqli,false,89 +BenchmarkTest02730,sqli,false,89 +BenchmarkTest02731,sqli,false,89 +BenchmarkTest02732,sqli,false,89 +BenchmarkTest02733,sqli,false,89 +BenchmarkTest02734,sqli,false,89 +BenchmarkTest02735,sqli,false,89 +BenchmarkTest02736,sqli,false,89 +BenchmarkTest02737,sqli,false,89 +BenchmarkTest02738,sqli,false,89 +BenchmarkTest02739,sqli,false,89 +BenchmarkTest02740,sqli,false,89